add tests for i types

This commit is contained in:
collin 2020-07-15 21:55:45 -07:00
parent 2f39ecdbc3
commit fe2f29ccad
74 changed files with 630 additions and 13 deletions

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> i128 {
return a + b
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) {
assert_eq!(a, b);
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> i128 {
return a / b
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> bool {
return a == b
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> bool {
return a >= b
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> bool {
return a > b
}

View File

@ -0,0 +1,3 @@
function main(x: i128) -> i128 {
return x
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> bool {
return a <= b
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> bool {
return a < b
}

View File

@ -0,0 +1,3 @@
function main() -> i128 {
return 170141183460469231731687303715884105727
}

View File

@ -0,0 +1,3 @@
function main() -> i128 {
return -170141183460469231731687303715884105728
}

View File

@ -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();
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> i128 {
return a * b
}

View File

@ -0,0 +1,3 @@
function main() -> i128 {
return 1
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> i128 {
return a ** b
}

View File

@ -0,0 +1,3 @@
function main(a: i128, b: i128) -> i128 {
return a - b
}

View File

@ -0,0 +1,3 @@
function main(b: bool, x: i128, y: i128) -> i128 {
return if b ? x : y
}

View File

@ -0,0 +1,3 @@
function main() -> i128 {
return 0
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> i16 {
return a + b
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) {
assert_eq!(a, b);
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> i16 {
return a / b
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> bool {
return a == b
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> bool {
return a >= b
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> bool {
return a > b
}

View File

@ -0,0 +1,3 @@
function main(x: i16) -> i16 {
return x
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> bool {
return a <= b
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> bool {
return a < b
}

View File

@ -0,0 +1,3 @@
function main() -> i16 {
return 32767
}

View File

@ -0,0 +1,3 @@
function main() -> i16 {
return -32768
}

View File

@ -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();
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> i16 {
return a * b
}

View File

@ -0,0 +1,3 @@
function main() -> i16 {
return 1
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> i16 {
return a ** b
}

View File

@ -0,0 +1,3 @@
function main(a: i16, b: i16) -> i16 {
return a - b
}

View File

@ -0,0 +1,3 @@
function main(b: bool, x: i16, y: i16) -> i16 {
return if b ? x : y
}

View File

@ -0,0 +1,3 @@
function main() -> i16 {
return 0
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> i32 {
return a + b
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) {
assert_eq!(a, b);
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> i32 {
return a / b
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> bool {
return a == b
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> bool {
return a >= b
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> bool {
return a > b
}

View File

@ -0,0 +1,3 @@
function main(x: i32) -> i32 {
return x
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> bool {
return a <= b
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> bool {
return a < b
}

View File

@ -0,0 +1,3 @@
function main() -> i32 {
return 2147483647
}

View File

@ -0,0 +1,3 @@
function main() -> i32 {
return -2147483648
}

View File

@ -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();
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> i32 {
return a * b
}

View File

@ -0,0 +1,3 @@
function main() -> i32 {
return 1
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> i32 {
return a ** b
}

View File

@ -0,0 +1,3 @@
function main(a: i32, b: i32) -> i32 {
return a - b
}

View File

@ -0,0 +1,3 @@
function main(b: bool, x: i32, y: i32) -> i32 {
return if b ? x : y
}

View File

@ -0,0 +1,3 @@
function main() -> i32 {
return 0
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> i64 {
return a + b
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) {
assert_eq!(a, b);
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> i64 {
return a / b
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> bool {
return a == b
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> bool {
return a >= b
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> bool {
return a > b
}

View File

@ -0,0 +1,3 @@
function main(x: i64) -> i64 {
return x
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> bool {
return a <= b
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> bool {
return a < b
}

View File

@ -0,0 +1,3 @@
function main() -> i64 {
return 9223372036854775807
}

View File

@ -0,0 +1,3 @@
function main() -> i64 {
return -9223372036854775808
}

View File

@ -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();
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> i64 {
return a * b
}

View File

@ -0,0 +1,3 @@
function main() -> i64 {
return 1
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> i64 {
return a ** b
}

View File

@ -0,0 +1,3 @@
function main(a: i64, b: i64) -> i64 {
return a - b
}

View File

@ -0,0 +1,3 @@
function main(b: bool, x: i64, y: i64) -> i64 {
return if b ? x : y
}

View File

@ -0,0 +1,3 @@
function main() -> i64 {
return 0
}

View File

@ -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;

View File

@ -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::<Fr>::new();
let res = one.less_than(cs.ns(|| "less than"), &two).unwrap();
println!("{}", res.get_value().unwrap());
}