2020-06-06 00:09:12 +03:00
|
|
|
macro_rules! test_uint {
|
2020-07-17 07:27:40 +03:00
|
|
|
($name: ident, $type_: ty, $integer_type: expr, $gadget: ty) => {
|
2020-06-06 00:09:12 +03:00
|
|
|
pub struct $name {}
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
impl IntegerTester for $name {
|
|
|
|
fn test_min() {
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("min.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
fn test_min_fail() {
|
|
|
|
let bytes = include_bytes!("min_fail.leo");
|
2020-06-09 05:13:47 +03:00
|
|
|
let program = parse_program(bytes).unwrap();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-08-01 00:06:01 +03:00
|
|
|
expect_parsing_error(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
fn test_max() {
|
|
|
|
let bytes = include_bytes!("max.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
|
|
|
}
|
2020-06-09 05:13:47 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
fn test_max_fail() {
|
|
|
|
let bytes = include_bytes!("max_fail.leo");
|
|
|
|
let program = parse_program(bytes).unwrap();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-08-01 00:06:01 +03:00
|
|
|
expect_parsing_error(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_add() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let c = match a.checked_add(b) {
|
|
|
|
Some(valid) => valid,
|
|
|
|
None => continue,
|
|
|
|
};
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("add.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
|
2020-06-06 00:09:12 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_sub() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let c = match a.checked_sub(b) {
|
2020-07-16 05:55:04 +03:00
|
|
|
Some(valid) => valid,
|
|
|
|
None => continue,
|
|
|
|
};
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("sub.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
|
2020-06-06 00:09:12 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_mul() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let c = match a.checked_mul(b) {
|
|
|
|
Some(valid) => valid,
|
|
|
|
None => continue,
|
|
|
|
};
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("mul.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
|
2020-06-06 00:09:12 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_div() {
|
2020-07-31 01:41:03 +03:00
|
|
|
for _ in 0..10 {
|
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let c = match a.checked_div(b) {
|
|
|
|
Some(valid) => valid,
|
|
|
|
None => continue,
|
|
|
|
};
|
2020-06-09 05:13:47 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let bytes = include_bytes!("div.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
|
|
|
|
]);
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-06-14 03:43:59 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_pow() {
|
2020-07-31 01:41:03 +03:00
|
|
|
for _ in 0..10 {
|
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
// rust specific conversion see https://doc.rust-lang.org/std/primitive.u8.html#method.checked_pow
|
|
|
|
let c = match a.checked_pow(b as u32) {
|
|
|
|
Some(valid) => valid,
|
|
|
|
None => continue,
|
|
|
|
};
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let bytes = include_bytes!("pow.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, c.to_string()))),
|
|
|
|
]);
|
2020-06-09 05:13:47 +03:00
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-06-06 00:09:12 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
|
|
|
}
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
fn test_eq() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test equal
|
2020-07-31 01:41:03 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("eq.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(true))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test not equal
|
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let c = a.eq(&b);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(c))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_ge() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test equal
|
2020-07-31 01:41:03 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("ge.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(true))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
// test greater or equal
|
|
|
|
|
|
|
|
let c = a.ge(&b);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(c))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_gt() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test equal
|
2020-07-31 01:41:03 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("gt.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(false))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
// test greater than
|
|
|
|
|
|
|
|
let c = a.gt(&b);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(c))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_le() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test equal
|
2020-07-31 01:41:03 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("le.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(true))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
assert_satisfied(program);
|
|
|
|
|
|
|
|
// test less or equal
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
let c = a.le(&b);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(c))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_lt() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test equal
|
2020-07-31 01:41:03 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("lt.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(false))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
// test less or equal
|
|
|
|
|
|
|
|
let c = a.lt(&b);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Boolean(c))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_assert_eq() {
|
|
|
|
for _ in 0..10 {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test equal
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("assert_eq.leo");
|
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, a.to_string()))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
|
|
|
// test not equal
|
2020-07-31 01:41:03 +03:00
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-31 01:41:03 +03:00
|
|
|
if a == b {
|
2020-06-06 01:34:06 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
expect_synthesis_error(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_ternary() {
|
2020-07-31 01:41:03 +03:00
|
|
|
let a: $type_ = rand::random();
|
|
|
|
let b: $type_ = rand::random();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-06-09 05:13:47 +03:00
|
|
|
let bytes = include_bytes!("ternary.leo");
|
2020-07-31 01:41:03 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-08 13:30:15 +03:00
|
|
|
// true -> field 1
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("s", Some(InputValue::Boolean(true))),
|
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, a.to_string()))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
|
2020-07-08 13:30:15 +03:00
|
|
|
// false -> field 2
|
2020-07-31 01:41:03 +03:00
|
|
|
let mut program = parse_program(bytes).unwrap();
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
let main_input = generate_main_input(vec![
|
2020-07-31 01:41:03 +03:00
|
|
|
("s", Some(InputValue::Boolean(false))),
|
|
|
|
("a", Some(InputValue::Integer($integer_type, a.to_string()))),
|
|
|
|
("b", Some(InputValue::Integer($integer_type, b.to_string()))),
|
|
|
|
("c", Some(InputValue::Integer($integer_type, b.to_string()))),
|
2020-06-06 01:34:06 +03:00
|
|
|
]);
|
|
|
|
|
2020-08-01 06:59:50 +03:00
|
|
|
program.set_main_input(main_input);
|
2020-07-31 01:41:03 +03:00
|
|
|
|
|
|
|
assert_satisfied(program);
|
2020-06-06 01:34:06 +03:00
|
|
|
}
|
2020-06-06 00:09:12 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|