Literals
Literals are constant values defined within the program rather than provided by a party.
Integer
Integer
represents a literal integer value. This value can be a negative integer, a positive integer, or zero.
- Nada program
- Test file
src/addition_literal.py
from nada_dsl import *
def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
num_1 = SecretInteger(Input(name="num_1", party=party_alice))
num_2 = SecretInteger(Input(name="num_2", party=party_bob))
literal = Integer(7)
sum = num_1 + num_2 + literal
return [Output(sum, "sum", party_charlie)]
tests/addition_literal_test.yaml
---
program: addition_literal
inputs:
num_1: 3
num_2: -3
expected_outputs:
sum: 7
Run and test the addition_literal program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run addition_literal_test
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test addition_literal_test
UnsignedInteger
UnsignedInteger
represents a literal unsigned integer value. This value can be zero or a positive integer.
- Nada program
- Test file
src/addition_literal_unsigned.py
from nada_dsl import *
def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
num_1 = SecretUnsignedInteger(Input(name="num_1", party=party_alice))
num_2 = SecretUnsignedInteger(Input(name="num_2", party=party_bob))
literal = UnsignedInteger(7)
sum = num_1 + num_2 + literal
return [Output(sum, "sum", party_charlie)]
tests/addition_literal_unsigned_test.yaml
---
program: addition_literal_unsigned
inputs:
num_1: 3
num_2: 3
expected_outputs:
sum: 13
Run and test the addition_literal_unsigned program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run addition_literal_unsigned_test
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test addition_literal_unsigned_test
Boolean
Boolean
represents a literal boolean value defined within the program rather than provided by a party. This value can be true or false.
- Nada program
- Test file
src/literal_boolean.py
from nada_dsl import *
def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
# Start value for literal boolean
is_sum_greater_than_five = Boolean(False)
public_num_1 = PublicInteger(Input(name="public_num_1", party=party_alice))
public_num_2 = PublicInteger(Input(name="public_num_2", party=party_bob))
is_sum_greater_than_five = (public_num_1 + public_num_2) > Integer(5)
return [Output(is_sum_greater_than_five, "result", party_charlie)]
tests/literal_boolean_test.yaml
---
program: literal_boolean
inputs:
public_num_1: 1
public_num_2: 3
expected_outputs:
result: false
Run and test the literal_boolean program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run literal_boolean_test
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test literal_boolean_test