From fe2f29ccad74afdc4aba4ae264563f2beb67bed4 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 15 Jul 2020 21:55:45 -0700 Subject: [PATCH] add tests for i types --- compiler/tests/integers/i128/add.leo | 3 + compiler/tests/integers/i128/assert_eq.leo | 3 + compiler/tests/integers/i128/div.leo | 3 + compiler/tests/integers/i128/eq.leo | 3 + compiler/tests/integers/i128/ge.leo | 3 + compiler/tests/integers/i128/gt.leo | 3 + compiler/tests/integers/i128/input.leo | 3 + compiler/tests/integers/i128/le.leo | 3 + compiler/tests/integers/i128/lt.leo | 3 + compiler/tests/integers/i128/max.leo | 3 + compiler/tests/integers/i128/min.leo | 3 + compiler/tests/integers/i128/mod.rs | 106 +++++++++++++++++++++ compiler/tests/integers/i128/mul.leo | 3 + compiler/tests/integers/i128/one.leo | 3 + compiler/tests/integers/i128/pow.leo | 3 + compiler/tests/integers/i128/sub.leo | 3 + compiler/tests/integers/i128/ternary.leo | 3 + compiler/tests/integers/i128/zero.leo | 3 + compiler/tests/integers/i16/add.leo | 3 + compiler/tests/integers/i16/assert_eq.leo | 3 + compiler/tests/integers/i16/div.leo | 3 + compiler/tests/integers/i16/eq.leo | 3 + compiler/tests/integers/i16/ge.leo | 3 + compiler/tests/integers/i16/gt.leo | 3 + compiler/tests/integers/i16/input.leo | 3 + compiler/tests/integers/i16/le.leo | 3 + compiler/tests/integers/i16/lt.leo | 3 + compiler/tests/integers/i16/max.leo | 3 + compiler/tests/integers/i16/min.leo | 3 + compiler/tests/integers/i16/mod.rs | 105 ++++++++++++++++++++ compiler/tests/integers/i16/mul.leo | 3 + compiler/tests/integers/i16/one.leo | 3 + compiler/tests/integers/i16/pow.leo | 3 + compiler/tests/integers/i16/sub.leo | 3 + compiler/tests/integers/i16/ternary.leo | 3 + compiler/tests/integers/i16/zero.leo | 3 + compiler/tests/integers/i32/add.leo | 3 + compiler/tests/integers/i32/assert_eq.leo | 3 + compiler/tests/integers/i32/div.leo | 3 + compiler/tests/integers/i32/eq.leo | 3 + compiler/tests/integers/i32/ge.leo | 3 + compiler/tests/integers/i32/gt.leo | 3 + compiler/tests/integers/i32/input.leo | 3 + compiler/tests/integers/i32/le.leo | 3 + compiler/tests/integers/i32/lt.leo | 3 + compiler/tests/integers/i32/max.leo | 3 + compiler/tests/integers/i32/min.leo | 3 + compiler/tests/integers/i32/mod.rs | 105 ++++++++++++++++++++ compiler/tests/integers/i32/mul.leo | 3 + compiler/tests/integers/i32/one.leo | 3 + compiler/tests/integers/i32/pow.leo | 3 + compiler/tests/integers/i32/sub.leo | 3 + compiler/tests/integers/i32/ternary.leo | 3 + compiler/tests/integers/i32/zero.leo | 3 + compiler/tests/integers/i64/add.leo | 3 + compiler/tests/integers/i64/assert_eq.leo | 3 + compiler/tests/integers/i64/div.leo | 3 + compiler/tests/integers/i64/eq.leo | 3 + compiler/tests/integers/i64/ge.leo | 3 + compiler/tests/integers/i64/gt.leo | 3 + compiler/tests/integers/i64/input.leo | 3 + compiler/tests/integers/i64/le.leo | 3 + compiler/tests/integers/i64/lt.leo | 3 + compiler/tests/integers/i64/max.leo | 3 + compiler/tests/integers/i64/min.leo | 3 + compiler/tests/integers/i64/mod.rs | 106 +++++++++++++++++++++ compiler/tests/integers/i64/mul.leo | 3 + compiler/tests/integers/i64/one.leo | 3 + compiler/tests/integers/i64/pow.leo | 3 + compiler/tests/integers/i64/sub.leo | 3 + compiler/tests/integers/i64/ternary.leo | 3 + compiler/tests/integers/i64/zero.leo | 3 + compiler/tests/integers/mod.rs | 4 + gadgets/tests/signed_integer/i8.rs | 13 --- 74 files changed, 630 insertions(+), 13 deletions(-) create mode 100644 compiler/tests/integers/i128/add.leo create mode 100644 compiler/tests/integers/i128/assert_eq.leo create mode 100644 compiler/tests/integers/i128/div.leo create mode 100644 compiler/tests/integers/i128/eq.leo create mode 100644 compiler/tests/integers/i128/ge.leo create mode 100644 compiler/tests/integers/i128/gt.leo create mode 100644 compiler/tests/integers/i128/input.leo create mode 100644 compiler/tests/integers/i128/le.leo create mode 100644 compiler/tests/integers/i128/lt.leo create mode 100644 compiler/tests/integers/i128/max.leo create mode 100644 compiler/tests/integers/i128/min.leo create mode 100644 compiler/tests/integers/i128/mod.rs create mode 100644 compiler/tests/integers/i128/mul.leo create mode 100644 compiler/tests/integers/i128/one.leo create mode 100644 compiler/tests/integers/i128/pow.leo create mode 100644 compiler/tests/integers/i128/sub.leo create mode 100644 compiler/tests/integers/i128/ternary.leo create mode 100644 compiler/tests/integers/i128/zero.leo create mode 100644 compiler/tests/integers/i16/add.leo create mode 100644 compiler/tests/integers/i16/assert_eq.leo create mode 100644 compiler/tests/integers/i16/div.leo create mode 100644 compiler/tests/integers/i16/eq.leo create mode 100644 compiler/tests/integers/i16/ge.leo create mode 100644 compiler/tests/integers/i16/gt.leo create mode 100644 compiler/tests/integers/i16/input.leo create mode 100644 compiler/tests/integers/i16/le.leo create mode 100644 compiler/tests/integers/i16/lt.leo create mode 100644 compiler/tests/integers/i16/max.leo create mode 100644 compiler/tests/integers/i16/min.leo create mode 100644 compiler/tests/integers/i16/mod.rs create mode 100644 compiler/tests/integers/i16/mul.leo create mode 100644 compiler/tests/integers/i16/one.leo create mode 100644 compiler/tests/integers/i16/pow.leo create mode 100644 compiler/tests/integers/i16/sub.leo create mode 100644 compiler/tests/integers/i16/ternary.leo create mode 100644 compiler/tests/integers/i16/zero.leo create mode 100644 compiler/tests/integers/i32/add.leo create mode 100644 compiler/tests/integers/i32/assert_eq.leo create mode 100644 compiler/tests/integers/i32/div.leo create mode 100644 compiler/tests/integers/i32/eq.leo create mode 100644 compiler/tests/integers/i32/ge.leo create mode 100644 compiler/tests/integers/i32/gt.leo create mode 100644 compiler/tests/integers/i32/input.leo create mode 100644 compiler/tests/integers/i32/le.leo create mode 100644 compiler/tests/integers/i32/lt.leo create mode 100644 compiler/tests/integers/i32/max.leo create mode 100644 compiler/tests/integers/i32/min.leo create mode 100644 compiler/tests/integers/i32/mod.rs create mode 100644 compiler/tests/integers/i32/mul.leo create mode 100644 compiler/tests/integers/i32/one.leo create mode 100644 compiler/tests/integers/i32/pow.leo create mode 100644 compiler/tests/integers/i32/sub.leo create mode 100644 compiler/tests/integers/i32/ternary.leo create mode 100644 compiler/tests/integers/i32/zero.leo create mode 100644 compiler/tests/integers/i64/add.leo create mode 100644 compiler/tests/integers/i64/assert_eq.leo create mode 100644 compiler/tests/integers/i64/div.leo create mode 100644 compiler/tests/integers/i64/eq.leo create mode 100644 compiler/tests/integers/i64/ge.leo create mode 100644 compiler/tests/integers/i64/gt.leo create mode 100644 compiler/tests/integers/i64/input.leo create mode 100644 compiler/tests/integers/i64/le.leo create mode 100644 compiler/tests/integers/i64/lt.leo create mode 100644 compiler/tests/integers/i64/max.leo create mode 100644 compiler/tests/integers/i64/min.leo create mode 100644 compiler/tests/integers/i64/mod.rs create mode 100644 compiler/tests/integers/i64/mul.leo create mode 100644 compiler/tests/integers/i64/one.leo create mode 100644 compiler/tests/integers/i64/pow.leo create mode 100644 compiler/tests/integers/i64/sub.leo create mode 100644 compiler/tests/integers/i64/ternary.leo create mode 100644 compiler/tests/integers/i64/zero.leo diff --git a/compiler/tests/integers/i128/add.leo b/compiler/tests/integers/i128/add.leo new file mode 100644 index 0000000000..9d6ceea8a3 --- /dev/null +++ b/compiler/tests/integers/i128/add.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> i128 { + return a + b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/assert_eq.leo b/compiler/tests/integers/i128/assert_eq.leo new file mode 100644 index 0000000000..2d50f08cdf --- /dev/null +++ b/compiler/tests/integers/i128/assert_eq.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) { + assert_eq!(a, b); +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/div.leo b/compiler/tests/integers/i128/div.leo new file mode 100644 index 0000000000..16f92be545 --- /dev/null +++ b/compiler/tests/integers/i128/div.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> i128 { + return a / b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/eq.leo b/compiler/tests/integers/i128/eq.leo new file mode 100644 index 0000000000..cdcbce828f --- /dev/null +++ b/compiler/tests/integers/i128/eq.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> bool { + return a == b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/ge.leo b/compiler/tests/integers/i128/ge.leo new file mode 100644 index 0000000000..6d134a4668 --- /dev/null +++ b/compiler/tests/integers/i128/ge.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> bool { + return a >= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/gt.leo b/compiler/tests/integers/i128/gt.leo new file mode 100644 index 0000000000..a636e26031 --- /dev/null +++ b/compiler/tests/integers/i128/gt.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> bool { + return a > b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/input.leo b/compiler/tests/integers/i128/input.leo new file mode 100644 index 0000000000..607901c4ef --- /dev/null +++ b/compiler/tests/integers/i128/input.leo @@ -0,0 +1,3 @@ +function main(x: i128) -> i128 { + return x +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/le.leo b/compiler/tests/integers/i128/le.leo new file mode 100644 index 0000000000..f1dcf57aa2 --- /dev/null +++ b/compiler/tests/integers/i128/le.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> bool { + return a <= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/lt.leo b/compiler/tests/integers/i128/lt.leo new file mode 100644 index 0000000000..cc435a7693 --- /dev/null +++ b/compiler/tests/integers/i128/lt.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> bool { + return a < b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/max.leo b/compiler/tests/integers/i128/max.leo new file mode 100644 index 0000000000..78886944d9 --- /dev/null +++ b/compiler/tests/integers/i128/max.leo @@ -0,0 +1,3 @@ +function main() -> i128 { + return 170141183460469231731687303715884105727 +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/min.leo b/compiler/tests/integers/i128/min.leo new file mode 100644 index 0000000000..561b2fe366 --- /dev/null +++ b/compiler/tests/integers/i128/min.leo @@ -0,0 +1,3 @@ +function main() -> i128 { + return -170141183460469231731687303715884105728 +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/mod.rs b/compiler/tests/integers/i128/mod.rs new file mode 100644 index 0000000000..789fe2af5a --- /dev/null +++ b/compiler/tests/integers/i128/mod.rs @@ -0,0 +1,106 @@ +use crate::{ + boolean::{output_expected_boolean, output_false, output_true}, + get_error, + get_output, + integers::{fail_integer, IntegerTester}, + parse_program, + EdwardsConstrainedValue, + EdwardsTestCompiler, +}; +use leo_compiler::{ConstrainedValue, Integer}; +use leo_gadgets::*; +use leo_inputs::types::{I128Type, IntegerType}; +use leo_types::InputValue; + +use snarkos_curves::edwards_bls12::Fq; +use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; + +fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int128) { + let output = get_output(program); + + match output { + EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { + [ConstrainedValue::Integer(Integer::I128(actual))] => assert_eq!(*actual, expected), + _ => panic!("program output unknown return value"), + }, + _ => panic!("program output unknown return value"), + } +} + +test_int!(TestI128, i128, IntegerType::I128Type(I128Type {}), Int128); + +#[test] +fn test_i128_min() { + TestI128::test_min(std::i128::MIN); +} + +#[test] +fn test_i128_max() { + TestI128::test_max(std::i128::MAX); +} + +#[test] +fn test_i128_input() { + TestI128::test_input(); +} + +#[test] +fn test_i128_add() { + TestI128::test_add(); +} + +#[test] +fn test_i128_sub() { + TestI128::test_sub(); +} + +#[test] +fn test_i128_mul() { + TestI128::test_mul(); +} + +#[test] +#[ignore] // this test takes ~5 mins +fn test_i128_div() { + TestI128::test_div(); +} + +#[test] +fn test_i128_pow() { + TestI128::test_pow(); +} + +#[test] +fn test_i128_eq() { + TestI128::test_eq(); +} + +#[test] +fn test_i128_ge() { + TestI128::test_ge(); +} + +#[test] +fn test_i128_gt() { + TestI128::test_gt(); +} + +#[test] +fn test_i128_le() { + TestI128::test_le(); +} + +#[test] +fn test_i128_lt() { + TestI128::test_lt(); +} + +#[test] +fn test_i128_assert_eq() { + TestI128::test_assert_eq(); +} + +#[test] +fn test_i128_ternary() { + TestI128::test_ternary(); +} diff --git a/compiler/tests/integers/i128/mul.leo b/compiler/tests/integers/i128/mul.leo new file mode 100644 index 0000000000..8fa04f0e29 --- /dev/null +++ b/compiler/tests/integers/i128/mul.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> i128 { + return a * b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/one.leo b/compiler/tests/integers/i128/one.leo new file mode 100644 index 0000000000..94313ac666 --- /dev/null +++ b/compiler/tests/integers/i128/one.leo @@ -0,0 +1,3 @@ +function main() -> i128 { + return 1 +} diff --git a/compiler/tests/integers/i128/pow.leo b/compiler/tests/integers/i128/pow.leo new file mode 100644 index 0000000000..7f94d84042 --- /dev/null +++ b/compiler/tests/integers/i128/pow.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> i128 { + return a ** b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/sub.leo b/compiler/tests/integers/i128/sub.leo new file mode 100644 index 0000000000..c8d0906a67 --- /dev/null +++ b/compiler/tests/integers/i128/sub.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) -> i128 { + return a - b +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/ternary.leo b/compiler/tests/integers/i128/ternary.leo new file mode 100644 index 0000000000..e566065f9d --- /dev/null +++ b/compiler/tests/integers/i128/ternary.leo @@ -0,0 +1,3 @@ +function main(b: bool, x: i128, y: i128) -> i128 { + return if b ? x : y +} \ No newline at end of file diff --git a/compiler/tests/integers/i128/zero.leo b/compiler/tests/integers/i128/zero.leo new file mode 100644 index 0000000000..e58cdfd4ff --- /dev/null +++ b/compiler/tests/integers/i128/zero.leo @@ -0,0 +1,3 @@ +function main() -> i128 { + return 0 +} diff --git a/compiler/tests/integers/i16/add.leo b/compiler/tests/integers/i16/add.leo new file mode 100644 index 0000000000..9e16e43ee7 --- /dev/null +++ b/compiler/tests/integers/i16/add.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> i16 { + return a + b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/assert_eq.leo b/compiler/tests/integers/i16/assert_eq.leo new file mode 100644 index 0000000000..4d86af7289 --- /dev/null +++ b/compiler/tests/integers/i16/assert_eq.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) { + assert_eq!(a, b); +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/div.leo b/compiler/tests/integers/i16/div.leo new file mode 100644 index 0000000000..829e3774de --- /dev/null +++ b/compiler/tests/integers/i16/div.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> i16 { + return a / b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/eq.leo b/compiler/tests/integers/i16/eq.leo new file mode 100644 index 0000000000..dfc367b414 --- /dev/null +++ b/compiler/tests/integers/i16/eq.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> bool { + return a == b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/ge.leo b/compiler/tests/integers/i16/ge.leo new file mode 100644 index 0000000000..2f8e1f7662 --- /dev/null +++ b/compiler/tests/integers/i16/ge.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> bool { + return a >= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/gt.leo b/compiler/tests/integers/i16/gt.leo new file mode 100644 index 0000000000..2667f2029c --- /dev/null +++ b/compiler/tests/integers/i16/gt.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> bool { + return a > b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/input.leo b/compiler/tests/integers/i16/input.leo new file mode 100644 index 0000000000..c9277c9df4 --- /dev/null +++ b/compiler/tests/integers/i16/input.leo @@ -0,0 +1,3 @@ +function main(x: i16) -> i16 { + return x +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/le.leo b/compiler/tests/integers/i16/le.leo new file mode 100644 index 0000000000..bc5422bdbe --- /dev/null +++ b/compiler/tests/integers/i16/le.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> bool { + return a <= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/lt.leo b/compiler/tests/integers/i16/lt.leo new file mode 100644 index 0000000000..57923d23ee --- /dev/null +++ b/compiler/tests/integers/i16/lt.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> bool { + return a < b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/max.leo b/compiler/tests/integers/i16/max.leo new file mode 100644 index 0000000000..d065fba813 --- /dev/null +++ b/compiler/tests/integers/i16/max.leo @@ -0,0 +1,3 @@ +function main() -> i16 { + return 32767 +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/min.leo b/compiler/tests/integers/i16/min.leo new file mode 100644 index 0000000000..42911c52aa --- /dev/null +++ b/compiler/tests/integers/i16/min.leo @@ -0,0 +1,3 @@ +function main() -> i16 { + return -32768 +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/mod.rs b/compiler/tests/integers/i16/mod.rs new file mode 100644 index 0000000000..bddaeb84be --- /dev/null +++ b/compiler/tests/integers/i16/mod.rs @@ -0,0 +1,105 @@ +use crate::{ + boolean::{output_expected_boolean, output_false, output_true}, + get_error, + get_output, + integers::{fail_integer, IntegerTester}, + parse_program, + EdwardsConstrainedValue, + EdwardsTestCompiler, +}; +use leo_compiler::{ConstrainedValue, Integer}; +use leo_gadgets::*; +use leo_inputs::types::{I16Type, IntegerType}; +use leo_types::InputValue; + +use snarkos_curves::edwards_bls12::Fq; +use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; + +fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int16) { + let output = get_output(program); + + match output { + EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { + [ConstrainedValue::Integer(Integer::I16(actual))] => assert_eq!(*actual, expected), + _ => panic!("program output unknown return value"), + }, + _ => panic!("program output unknown return value"), + } +} + +test_int!(TestI16, i16, IntegerType::I16Type(I16Type {}), Int16); + +#[test] +fn test_i16_min() { + TestI16::test_min(std::i16::MIN); +} + +#[test] +fn test_i16_max() { + TestI16::test_max(std::i16::MAX); +} + +#[test] +fn test_i16_input() { + TestI16::test_input(); +} + +#[test] +fn test_i16_add() { + TestI16::test_add(); +} + +#[test] +fn test_i16_sub() { + TestI16::test_sub(); +} + +#[test] +fn test_i16_mul() { + TestI16::test_mul(); +} + +#[test] +fn test_i16_div() { + TestI16::test_div(); +} + +#[test] +fn test_i16_pow() { + TestI16::test_pow(); +} + +#[test] +fn test_i16_eq() { + TestI16::test_eq(); +} + +#[test] +fn test_i16_ge() { + TestI16::test_ge(); +} + +#[test] +fn test_i16_gt() { + TestI16::test_gt(); +} + +#[test] +fn test_i16_le() { + TestI16::test_le(); +} + +#[test] +fn test_i16_lt() { + TestI16::test_lt(); +} + +#[test] +fn test_i16_assert_eq() { + TestI16::test_assert_eq(); +} + +#[test] +fn test_i16_ternary() { + TestI16::test_ternary(); +} diff --git a/compiler/tests/integers/i16/mul.leo b/compiler/tests/integers/i16/mul.leo new file mode 100644 index 0000000000..bd52e02f34 --- /dev/null +++ b/compiler/tests/integers/i16/mul.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> i16 { + return a * b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/one.leo b/compiler/tests/integers/i16/one.leo new file mode 100644 index 0000000000..40af477ea3 --- /dev/null +++ b/compiler/tests/integers/i16/one.leo @@ -0,0 +1,3 @@ +function main() -> i16 { + return 1 +} diff --git a/compiler/tests/integers/i16/pow.leo b/compiler/tests/integers/i16/pow.leo new file mode 100644 index 0000000000..9859121160 --- /dev/null +++ b/compiler/tests/integers/i16/pow.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> i16 { + return a ** b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/sub.leo b/compiler/tests/integers/i16/sub.leo new file mode 100644 index 0000000000..43a037e18f --- /dev/null +++ b/compiler/tests/integers/i16/sub.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) -> i16 { + return a - b +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/ternary.leo b/compiler/tests/integers/i16/ternary.leo new file mode 100644 index 0000000000..c8b5e7ea53 --- /dev/null +++ b/compiler/tests/integers/i16/ternary.leo @@ -0,0 +1,3 @@ +function main(b: bool, x: i16, y: i16) -> i16 { + return if b ? x : y +} \ No newline at end of file diff --git a/compiler/tests/integers/i16/zero.leo b/compiler/tests/integers/i16/zero.leo new file mode 100644 index 0000000000..781030f10a --- /dev/null +++ b/compiler/tests/integers/i16/zero.leo @@ -0,0 +1,3 @@ +function main() -> i16 { + return 0 +} diff --git a/compiler/tests/integers/i32/add.leo b/compiler/tests/integers/i32/add.leo new file mode 100644 index 0000000000..18a3826571 --- /dev/null +++ b/compiler/tests/integers/i32/add.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> i32 { + return a + b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/assert_eq.leo b/compiler/tests/integers/i32/assert_eq.leo new file mode 100644 index 0000000000..8981df48c3 --- /dev/null +++ b/compiler/tests/integers/i32/assert_eq.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) { + assert_eq!(a, b); +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/div.leo b/compiler/tests/integers/i32/div.leo new file mode 100644 index 0000000000..b86b6a0567 --- /dev/null +++ b/compiler/tests/integers/i32/div.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> i32 { + return a / b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/eq.leo b/compiler/tests/integers/i32/eq.leo new file mode 100644 index 0000000000..a92a53fb09 --- /dev/null +++ b/compiler/tests/integers/i32/eq.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> bool { + return a == b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/ge.leo b/compiler/tests/integers/i32/ge.leo new file mode 100644 index 0000000000..0587fbb02d --- /dev/null +++ b/compiler/tests/integers/i32/ge.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> bool { + return a >= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/gt.leo b/compiler/tests/integers/i32/gt.leo new file mode 100644 index 0000000000..0425fc8c81 --- /dev/null +++ b/compiler/tests/integers/i32/gt.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> bool { + return a > b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/input.leo b/compiler/tests/integers/i32/input.leo new file mode 100644 index 0000000000..3f3f06dfc5 --- /dev/null +++ b/compiler/tests/integers/i32/input.leo @@ -0,0 +1,3 @@ +function main(x: i32) -> i32 { + return x +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/le.leo b/compiler/tests/integers/i32/le.leo new file mode 100644 index 0000000000..1ee0a68839 --- /dev/null +++ b/compiler/tests/integers/i32/le.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> bool { + return a <= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/lt.leo b/compiler/tests/integers/i32/lt.leo new file mode 100644 index 0000000000..1bb461b028 --- /dev/null +++ b/compiler/tests/integers/i32/lt.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> bool { + return a < b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/max.leo b/compiler/tests/integers/i32/max.leo new file mode 100644 index 0000000000..af6d07a72f --- /dev/null +++ b/compiler/tests/integers/i32/max.leo @@ -0,0 +1,3 @@ +function main() -> i32 { + return 2147483647 +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/min.leo b/compiler/tests/integers/i32/min.leo new file mode 100644 index 0000000000..0638ed024e --- /dev/null +++ b/compiler/tests/integers/i32/min.leo @@ -0,0 +1,3 @@ +function main() -> i32 { + return -2147483648 +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/mod.rs b/compiler/tests/integers/i32/mod.rs new file mode 100644 index 0000000000..940379ad8d --- /dev/null +++ b/compiler/tests/integers/i32/mod.rs @@ -0,0 +1,105 @@ +use crate::{ + boolean::{output_expected_boolean, output_false, output_true}, + get_error, + get_output, + integers::{fail_integer, IntegerTester}, + parse_program, + EdwardsConstrainedValue, + EdwardsTestCompiler, +}; +use leo_compiler::{ConstrainedValue, Integer}; +use leo_gadgets::*; +use leo_inputs::types::{I32Type, IntegerType}; +use leo_types::InputValue; + +use snarkos_curves::edwards_bls12::Fq; +use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; + +fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int32) { + let output = get_output(program); + + match output { + EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { + [ConstrainedValue::Integer(Integer::I32(actual))] => assert_eq!(*actual, expected), + _ => panic!("program output unknown return value"), + }, + _ => panic!("program output unknown return value"), + } +} + +test_int!(TestI32, i32, IntegerType::I32Type(I32Type {}), Int32); + +#[test] +fn test_i32_min() { + TestI32::test_min(std::i32::MIN); +} + +#[test] +fn test_i32_max() { + TestI32::test_max(std::i32::MAX); +} + +#[test] +fn test_i32_input() { + TestI32::test_input(); +} + +#[test] +fn test_i32_add() { + TestI32::test_add(); +} + +#[test] +fn test_i32_sub() { + TestI32::test_sub(); +} + +#[test] +fn test_i32_mul() { + TestI32::test_mul(); +} + +#[test] +fn test_i32_div() { + TestI32::test_div(); +} + +#[test] +fn test_i32_pow() { + TestI32::test_pow(); +} + +#[test] +fn test_i32_eq() { + TestI32::test_eq(); +} + +#[test] +fn test_i32_ge() { + TestI32::test_ge(); +} + +#[test] +fn test_i32_gt() { + TestI32::test_gt(); +} + +#[test] +fn test_i32_le() { + TestI32::test_le(); +} + +#[test] +fn test_i32_lt() { + TestI32::test_lt(); +} + +#[test] +fn test_i32_assert_eq() { + TestI32::test_assert_eq(); +} + +#[test] +fn test_i32_ternary() { + TestI32::test_ternary(); +} diff --git a/compiler/tests/integers/i32/mul.leo b/compiler/tests/integers/i32/mul.leo new file mode 100644 index 0000000000..bb79535b60 --- /dev/null +++ b/compiler/tests/integers/i32/mul.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> i32 { + return a * b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/one.leo b/compiler/tests/integers/i32/one.leo new file mode 100644 index 0000000000..5ef3894d5e --- /dev/null +++ b/compiler/tests/integers/i32/one.leo @@ -0,0 +1,3 @@ +function main() -> i32 { + return 1 +} diff --git a/compiler/tests/integers/i32/pow.leo b/compiler/tests/integers/i32/pow.leo new file mode 100644 index 0000000000..726ac0881b --- /dev/null +++ b/compiler/tests/integers/i32/pow.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> i32 { + return a ** b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/sub.leo b/compiler/tests/integers/i32/sub.leo new file mode 100644 index 0000000000..dd7a99431c --- /dev/null +++ b/compiler/tests/integers/i32/sub.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) -> i32 { + return a - b +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/ternary.leo b/compiler/tests/integers/i32/ternary.leo new file mode 100644 index 0000000000..e5901b40e4 --- /dev/null +++ b/compiler/tests/integers/i32/ternary.leo @@ -0,0 +1,3 @@ +function main(b: bool, x: i32, y: i32) -> i32 { + return if b ? x : y +} \ No newline at end of file diff --git a/compiler/tests/integers/i32/zero.leo b/compiler/tests/integers/i32/zero.leo new file mode 100644 index 0000000000..53922fcf02 --- /dev/null +++ b/compiler/tests/integers/i32/zero.leo @@ -0,0 +1,3 @@ +function main() -> i32 { + return 0 +} diff --git a/compiler/tests/integers/i64/add.leo b/compiler/tests/integers/i64/add.leo new file mode 100644 index 0000000000..bfa486e639 --- /dev/null +++ b/compiler/tests/integers/i64/add.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> i64 { + return a + b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/assert_eq.leo b/compiler/tests/integers/i64/assert_eq.leo new file mode 100644 index 0000000000..8488ef8eb8 --- /dev/null +++ b/compiler/tests/integers/i64/assert_eq.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) { + assert_eq!(a, b); +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/div.leo b/compiler/tests/integers/i64/div.leo new file mode 100644 index 0000000000..3ab271bf0a --- /dev/null +++ b/compiler/tests/integers/i64/div.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> i64 { + return a / b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/eq.leo b/compiler/tests/integers/i64/eq.leo new file mode 100644 index 0000000000..bbbbfaebd7 --- /dev/null +++ b/compiler/tests/integers/i64/eq.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> bool { + return a == b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/ge.leo b/compiler/tests/integers/i64/ge.leo new file mode 100644 index 0000000000..9cc166336c --- /dev/null +++ b/compiler/tests/integers/i64/ge.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> bool { + return a >= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/gt.leo b/compiler/tests/integers/i64/gt.leo new file mode 100644 index 0000000000..b3e40b4da7 --- /dev/null +++ b/compiler/tests/integers/i64/gt.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> bool { + return a > b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/input.leo b/compiler/tests/integers/i64/input.leo new file mode 100644 index 0000000000..0df21aab02 --- /dev/null +++ b/compiler/tests/integers/i64/input.leo @@ -0,0 +1,3 @@ +function main(x: i64) -> i64 { + return x +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/le.leo b/compiler/tests/integers/i64/le.leo new file mode 100644 index 0000000000..ada4d64619 --- /dev/null +++ b/compiler/tests/integers/i64/le.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> bool { + return a <= b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/lt.leo b/compiler/tests/integers/i64/lt.leo new file mode 100644 index 0000000000..782da7affe --- /dev/null +++ b/compiler/tests/integers/i64/lt.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> bool { + return a < b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/max.leo b/compiler/tests/integers/i64/max.leo new file mode 100644 index 0000000000..938e65bce1 --- /dev/null +++ b/compiler/tests/integers/i64/max.leo @@ -0,0 +1,3 @@ +function main() -> i64 { + return 9223372036854775807 +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/min.leo b/compiler/tests/integers/i64/min.leo new file mode 100644 index 0000000000..c8f3e38580 --- /dev/null +++ b/compiler/tests/integers/i64/min.leo @@ -0,0 +1,3 @@ +function main() -> i64 { + return -9223372036854775808 +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/mod.rs b/compiler/tests/integers/i64/mod.rs new file mode 100644 index 0000000000..0d5d817308 --- /dev/null +++ b/compiler/tests/integers/i64/mod.rs @@ -0,0 +1,106 @@ +use crate::{ + boolean::{output_expected_boolean, output_false, output_true}, + get_error, + get_output, + integers::{fail_integer, IntegerTester}, + parse_program, + EdwardsConstrainedValue, + EdwardsTestCompiler, +}; +use leo_compiler::{ConstrainedValue, Integer}; +use leo_gadgets::*; +use leo_inputs::types::{I64Type, IntegerType}; +use leo_types::InputValue; + +use snarkos_curves::edwards_bls12::Fq; +use snarkos_models::gadgets::{r1cs::TestConstraintSystem, utilities::alloc::AllocGadget}; + +fn output_expected_allocated(program: EdwardsTestCompiler, expected: Int64) { + let output = get_output(program); + + match output { + EdwardsConstrainedValue::Return(vec) => match vec.as_slice() { + [ConstrainedValue::Integer(Integer::I64(actual))] => assert_eq!(*actual, expected), + _ => panic!("program output unknown return value"), + }, + _ => panic!("program output unknown return value"), + } +} + +test_int!(TestI64, i64, IntegerType::I64Type(I64Type {}), Int64); + +#[test] +fn test_i64_min() { + TestI64::test_min(std::i64::MIN); +} + +#[test] +fn test_i64_max() { + TestI64::test_max(std::i64::MAX); +} + +#[test] +fn test_i64_input() { + TestI64::test_input(); +} + +#[test] +fn test_i64_add() { + TestI64::test_add(); +} + +#[test] +fn test_i64_sub() { + TestI64::test_sub(); +} + +#[test] +fn test_i64_mul() { + TestI64::test_mul(); +} + +#[test] +// #[ignore] // this test takes ~1 min +fn test_i64_div() { + TestI64::test_div(); +} + +#[test] +fn test_i64_pow() { + TestI64::test_pow(); +} + +#[test] +fn test_i64_eq() { + TestI64::test_eq(); +} + +#[test] +fn test_i64_ge() { + TestI64::test_ge(); +} + +#[test] +fn test_i64_gt() { + TestI64::test_gt(); +} + +#[test] +fn test_i64_le() { + TestI64::test_le(); +} + +#[test] +fn test_i64_lt() { + TestI64::test_lt(); +} + +#[test] +fn test_i64_assert_eq() { + TestI64::test_assert_eq(); +} + +#[test] +fn test_i64_ternary() { + TestI64::test_ternary(); +} diff --git a/compiler/tests/integers/i64/mul.leo b/compiler/tests/integers/i64/mul.leo new file mode 100644 index 0000000000..6740cd737a --- /dev/null +++ b/compiler/tests/integers/i64/mul.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> i64 { + return a * b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/one.leo b/compiler/tests/integers/i64/one.leo new file mode 100644 index 0000000000..c3fd8abc72 --- /dev/null +++ b/compiler/tests/integers/i64/one.leo @@ -0,0 +1,3 @@ +function main() -> i64 { + return 1 +} diff --git a/compiler/tests/integers/i64/pow.leo b/compiler/tests/integers/i64/pow.leo new file mode 100644 index 0000000000..871ba7865c --- /dev/null +++ b/compiler/tests/integers/i64/pow.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> i64 { + return a ** b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/sub.leo b/compiler/tests/integers/i64/sub.leo new file mode 100644 index 0000000000..6c8e074071 --- /dev/null +++ b/compiler/tests/integers/i64/sub.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) -> i64 { + return a - b +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/ternary.leo b/compiler/tests/integers/i64/ternary.leo new file mode 100644 index 0000000000..0710cc8490 --- /dev/null +++ b/compiler/tests/integers/i64/ternary.leo @@ -0,0 +1,3 @@ +function main(b: bool, x: i64, y: i64) -> i64 { + return if b ? x : y +} \ No newline at end of file diff --git a/compiler/tests/integers/i64/zero.leo b/compiler/tests/integers/i64/zero.leo new file mode 100644 index 0000000000..ce0a3bd9c2 --- /dev/null +++ b/compiler/tests/integers/i64/zero.leo @@ -0,0 +1,3 @@ +function main() -> i64 { + return 0 +} diff --git a/compiler/tests/integers/mod.rs b/compiler/tests/integers/mod.rs index b6c0706fa3..2abbeacf2e 100644 --- a/compiler/tests/integers/mod.rs +++ b/compiler/tests/integers/mod.rs @@ -14,4 +14,8 @@ pub mod u32; pub mod u64; pub mod u8; +pub mod i128; +pub mod i16; +pub mod i32; +pub mod i64; pub mod i8; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index 9cbeaec95a..e9b8a7eeb4 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -8,7 +8,6 @@ use snarkos_models::{ }, }; -use leo_gadgets::binary::EvaluateLtGadget; use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; use std::i8; @@ -405,15 +404,3 @@ fn test_int8_pow() { assert!(!cs.is_satisfied()); } } - -#[test] -fn i8_lt() { - let one = Int8::constant(1i8); - let two = Int8::constant(-9i8); - - let mut cs = TestConstraintSystem::::new(); - - let res = one.less_than(cs.ns(|| "less than"), &two).unwrap(); - - println!("{}", res.get_value().unwrap()); -}