Not
The NOT operator, represented by the tilde symbol (~), is used in the Nada DSL to invert or negate a boolean value. When applied to a boolean expression, the ~ operator flips its value—turning True to False and False to True.
- Nada program
- Test 1
- Test 2
src/not.py
from nada_dsl import *
def nada_main():
party_alice = Party(name="Alice")
party_bob = Party(name="Bob")
party_charlie = Party(name="Charlie")
secret_target = SecretInteger(Input(name="secret_target", party=party_alice))
secret_guess = SecretInteger(Input(name="secret_guess", party=party_bob))
# equal to check (==)
check_is_equal_to = secret_target == secret_guess
# the not operator (~) is used to invert or negate a boolean value
check_is_not_equal_to = ~check_is_equal_to
return [
Output(check_is_not_equal_to, "check_is_not_equal_to", party_charlie),
]
tests/not_test_1.yaml
---
program: not
inputs:
secret_guess: 30
secret_target: 3
expected_outputs:
check_is_not_equal_to: true
tests/not_test_2.yaml
---
program: not
inputs:
secret_guess: 3
secret_target: 3
expected_outputs:
check_is_not_equal_to: false
Run and test the not program
1. Open "Nada by Example"
2. Run the program with inputs
from the test file
nada run not_test_1
3. Test the program with inputs
from the test file against the expected_outputs
from the test file
nada test not_test_1