2020-05-21 03:08:32 +03:00
|
|
|
use crate::{
|
2020-06-08 07:26:49 +03:00
|
|
|
integers::u32::{output_one, output_zero},
|
2020-06-09 04:58:41 +03:00
|
|
|
parse_program,
|
2020-05-21 03:08:32 +03:00
|
|
|
};
|
2020-06-08 07:26:49 +03:00
|
|
|
use leo_types::InputValue;
|
2020-06-02 04:35:43 +03:00
|
|
|
|
2020-05-30 03:34:31 +03:00
|
|
|
use snarkos_curves::edwards_bls12::Fq;
|
2020-05-21 03:08:32 +03:00
|
|
|
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
|
|
|
|
2020-06-13 12:08:21 +03:00
|
|
|
pub mod conditional;
|
|
|
|
|
2020-05-21 03:08:32 +03:00
|
|
|
// Ternary if {bool}? {expression} : {expression};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ternary_basic() {
|
2020-06-09 04:58:41 +03:00
|
|
|
let bytes = include_bytes!("ternary_basic.leo");
|
|
|
|
let mut program_input_true = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-21 03:08:32 +03:00
|
|
|
let mut program_input_false = program_input_true.clone();
|
|
|
|
|
|
|
|
program_input_true.set_inputs(vec![Some(InputValue::Boolean(true))]);
|
|
|
|
output_one(program_input_true);
|
|
|
|
|
|
|
|
program_input_false.set_inputs(vec![Some(InputValue::Boolean(false))]);
|
|
|
|
output_zero(program_input_false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iteration for i {start}..{stop} { statements }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_iteration_basic() {
|
2020-06-09 04:58:41 +03:00
|
|
|
let bytes = include_bytes!("iteration_basic.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-05-21 03:08:32 +03:00
|
|
|
output_one(program);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assertion
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_assertion_basic() {
|
2020-06-09 04:58:41 +03:00
|
|
|
let bytes = include_bytes!("assertion_basic.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
2020-05-21 03:08:32 +03:00
|
|
|
|
|
|
|
let mut program_input_true = program.clone();
|
2020-05-30 02:43:39 +03:00
|
|
|
let mut cs_satisfied = TestConstraintSystem::<Fq>::new();
|
2020-05-21 03:08:32 +03:00
|
|
|
|
|
|
|
program_input_true.set_inputs(vec![Some(InputValue::Boolean(true))]);
|
2020-06-08 09:30:39 +03:00
|
|
|
let _output = program_input_true.compile_constraints(&mut cs_satisfied).unwrap();
|
2020-05-21 03:08:32 +03:00
|
|
|
|
|
|
|
assert!(cs_satisfied.is_satisfied());
|
|
|
|
|
|
|
|
let mut program_input_false = program.clone();
|
2020-05-30 02:43:39 +03:00
|
|
|
let mut cs_unsatisfied = TestConstraintSystem::<Fq>::new();
|
2020-05-21 03:08:32 +03:00
|
|
|
|
|
|
|
program_input_false.set_inputs(vec![Some(InputValue::Boolean(false))]);
|
2020-06-08 09:30:39 +03:00
|
|
|
let _output = program_input_false.compile_constraints(&mut cs_unsatisfied).unwrap();
|
2020-05-21 03:08:32 +03:00
|
|
|
|
|
|
|
assert!(!cs_unsatisfied.is_satisfied());
|
|
|
|
}
|