diff --git a/compiler/tests/integers/macros.rs b/compiler/tests/integers/macros.rs index 81eb459f98..710b55f217 100644 --- a/compiler/tests/integers/macros.rs +++ b/compiler/tests/integers/macros.rs @@ -74,7 +74,10 @@ macro_rules! test_uint { let r1: $_type = rand::random(); let r2: $_type = rand::random(); - let difference = r1.wrapping_sub(r2); + let difference = match r1.checked_sub(r2) { + Some(valid) => valid, + None => continue, + }; let cs = TestConstraintSystem::::new(); let difference_allocated = <$gadget>::alloc(cs, || Ok(difference)).unwrap(); diff --git a/compiler/tests/integers/u128/mod.rs b/compiler/tests/integers/u128/mod.rs index 800208b945..e1a8470c60 100644 --- a/compiler/tests/integers/u128/mod.rs +++ b/compiler/tests/integers/u128/mod.rs @@ -28,29 +28,80 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt128) { _ => panic!("program output unknown return value"), } } +test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128); #[test] -#[ignore] // temporarily ignore memory expensive tests for travis -fn test_u128() { - test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128); - +fn test_u128_min() { TestU128::test_min(std::u128::MIN); +} + +#[test] +fn test_u128_max() { TestU128::test_max(std::u128::MAX); +} +#[test] +fn test_u128_input() { TestU128::test_input(); +} +#[test] +fn test_u128_add() { TestU128::test_add(); - // TestU128::test_sub(); //Todo: Catch subtraction overflow error in gadget +} + +#[test] +fn test_u128_sub() { + TestU128::test_sub(); +} + +#[test] // this test take ~1 min +fn test_u128_mul() { TestU128::test_mul(); +} + +#[test] // this test takes ~30 sec +fn test_u128_div() { TestU128::test_div(); - // TestU128::test_pow(); // takes about 10 minutes +} +#[test] +#[ignore] // this test takes ~10 mins +fn test_u128_pow() { + TestU128::test_pow(); +} + +#[test] +fn test_u128_eq() { TestU128::test_eq(); - TestU128::test_ge(); - TestU128::test_gt(); - TestU128::test_le(); - TestU128::test_gt(); +} +#[test] +fn test_u128_ge() { + TestU128::test_ge(); +} + +#[test] +fn test_u128_gt() { + TestU128::test_gt(); +} + +#[test] +fn test_u128_le() { + TestU128::test_le(); +} + +#[test] +fn test_u128_lt() { + TestU128::test_lt(); +} + +#[test] +fn test_u128_assert_eq() { TestU128::test_assert_eq(); +} + +#[test] +fn test_u128_ternary() { TestU128::test_ternary(); } diff --git a/compiler/tests/integers/u16/mod.rs b/compiler/tests/integers/u16/mod.rs index 1c231abfcf..15534974e3 100644 --- a/compiler/tests/integers/u16/mod.rs +++ b/compiler/tests/integers/u16/mod.rs @@ -29,27 +29,79 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt16) { } } +test_uint!(TestU16, u16, IntegerType::U16Type(U16Type {}), UInt16); + #[test] -fn test_u16() { - test_uint!(Testu16, u16, IntegerType::U16Type(U16Type {}), UInt16); - - Testu16::test_min(std::u16::MIN); - Testu16::test_max(std::u16::MAX); - - Testu16::test_input(); - - Testu16::test_add(); - // Testu16::test_sub(); //Todo: Catch subtraction overflow error in gadget - Testu16::test_mul(); - Testu16::test_div(); - Testu16::test_pow(); - - Testu16::test_eq(); - Testu16::test_ge(); - Testu16::test_gt(); - Testu16::test_le(); - Testu16::test_gt(); - - Testu16::test_assert_eq(); - Testu16::test_ternary(); +fn test_u16_min() { + TestU16::test_min(std::u16::MIN); +} + +#[test] +fn test_u16_max() { + TestU16::test_max(std::u16::MAX); +} + +#[test] +fn test_u16_input() { + TestU16::test_input(); +} + +#[test] +fn test_u16_add() { + TestU16::test_add(); +} + +#[test] +fn test_u16_sub() { + TestU16::test_sub(); +} + +#[test] +fn test_u16_mul() { + TestU16::test_mul(); +} + +#[test] +fn test_u16_div() { + TestU16::test_div(); +} + +#[test] +fn test_u16_pow() { + TestU16::test_pow(); +} + +#[test] +fn test_u16_eq() { + TestU16::test_eq(); +} + +#[test] +fn test_u16_ge() { + TestU16::test_ge(); +} + +#[test] +fn test_u16_gt() { + TestU16::test_gt(); +} + +#[test] +fn test_u16_le() { + TestU16::test_le(); +} + +#[test] +fn test_u16_lt() { + TestU16::test_lt(); +} + +#[test] +fn test_u16_assert_eq() { + TestU16::test_assert_eq(); +} + +#[test] +fn test_u16_ternary() { + TestU16::test_ternary(); } diff --git a/compiler/tests/integers/u32/mod.rs b/compiler/tests/integers/u32/mod.rs index ec9cbb3d06..ce5cf6f951 100644 --- a/compiler/tests/integers/u32/mod.rs +++ b/compiler/tests/integers/u32/mod.rs @@ -46,43 +46,79 @@ pub(crate) fn output_one(program: EdwardsTestCompiler) { output_number(program, 1u32); } +test_uint!(TestU32, u32, IntegerType::U32Type(U32Type {}), UInt32); + #[test] -fn test_u32() { - test_uint!(TestU32, u32, IntegerType::U32Type(U32Type {}), UInt32); - +fn test_u32_min() { TestU32::test_min(std::u32::MIN); +} + +#[test] +fn test_u32_max() { TestU32::test_max(std::u32::MAX); +} +#[test] +fn test_u32_input() { TestU32::test_input(); +} +#[test] +fn test_u32_add() { TestU32::test_add(); - // TestU32::test_sub(); //Todo: Catch subtraction overflow error in gadget +} + +#[test] +fn test_u32_sub() { + TestU32::test_sub(); +} + +#[test] +fn test_u32_mul() { TestU32::test_mul(); +} + +#[test] +fn test_u32_div() { TestU32::test_div(); - TestU32::test_pow(); // takes about 2 mins +} +#[test] +fn test_u32_pow() { + TestU32::test_pow(); +} + +#[test] +fn test_u32_eq() { TestU32::test_eq(); - TestU32::test_ge(); - TestU32::test_gt(); - TestU32::test_le(); - TestU32::test_gt(); +} +#[test] +fn test_u32_ge() { + TestU32::test_ge(); +} + +#[test] +fn test_u32_gt() { + TestU32::test_gt(); +} + +#[test] +fn test_u32_le() { + TestU32::test_le(); +} + +#[test] +fn test_u32_lt() { + TestU32::test_lt(); +} + +#[test] +fn test_u32_assert_eq() { TestU32::test_assert_eq(); +} + +#[test] +fn test_u32_ternary() { TestU32::test_ternary(); } - -#[test] -fn test_zero() { - let bytes = include_bytes!("zero.leo"); - let program = parse_program(bytes).unwrap(); - - output_zero(program); -} - -#[test] -fn test_one() { - let bytes = include_bytes!("one.leo"); - let program = parse_program(bytes).unwrap(); - - output_one(program); -} diff --git a/compiler/tests/integers/u64/mod.rs b/compiler/tests/integers/u64/mod.rs index 5b5a277df1..924079e1c5 100644 --- a/compiler/tests/integers/u64/mod.rs +++ b/compiler/tests/integers/u64/mod.rs @@ -29,28 +29,80 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt64) { } } +test_uint!(TestU64, u64, IntegerType::U64Type(U64Type {}), UInt64); + #[test] -#[ignore] //temporarily ignore memory expensive tests for travis -fn test_u64() { - test_uint!(Testu64, u64, IntegerType::U64Type(U64Type {}), UInt64); - - Testu64::test_min(std::u64::MIN); - Testu64::test_max(std::u64::MAX); - - Testu64::test_input(); - - Testu64::test_add(); - // Testu64::test_sub(); //Todo: Catch subtraction overflow error in gadget - Testu64::test_mul(); - Testu64::test_div(); - Testu64::test_pow(); // takes ~2mins - - Testu64::test_eq(); - Testu64::test_ge(); - Testu64::test_gt(); - Testu64::test_le(); - Testu64::test_gt(); - - Testu64::test_assert_eq(); - Testu64::test_ternary(); +fn test_u64_min() { + TestU64::test_min(std::u64::MIN); +} + +#[test] +fn test_u64_max() { + TestU64::test_max(std::u64::MAX); +} + +#[test] +fn test_u64_input() { + TestU64::test_input(); +} + +#[test] +fn test_u64_add() { + TestU64::test_add(); +} + +#[test] +fn test_u64_sub() { + TestU64::test_sub(); +} + +#[test] +fn test_u64_mul() { + TestU64::test_mul(); +} + +#[test] +fn test_u64_div() { + TestU64::test_div(); +} + +#[test] +#[ignore] // this test takes ~7 mins +fn test_u64_pow() { + TestU64::test_pow(); +} + +#[test] +fn test_u64_eq() { + TestU64::test_eq(); +} + +#[test] +fn test_u64_ge() { + TestU64::test_ge(); +} + +#[test] +fn test_u64_gt() { + TestU64::test_gt(); +} + +#[test] +fn test_u64_le() { + TestU64::test_le(); +} + +#[test] +fn test_u64_lt() { + TestU64::test_lt(); +} + +#[test] +fn test_u64_assert_eq() { + TestU64::test_assert_eq(); +} + +#[test] +fn test_u64_ternary() { + TestU64::test_ternary(); } diff --git a/compiler/tests/integers/u8/mod.rs b/compiler/tests/integers/u8/mod.rs index ae0868860c..f872a6c3b9 100644 --- a/compiler/tests/integers/u8/mod.rs +++ b/compiler/tests/integers/u8/mod.rs @@ -29,27 +29,79 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt8) { } } +test_uint!(TestU8, u8, IntegerType::U8Type(U8Type {}), UInt8); + #[test] -fn test_u8() { - test_uint!(Testu8, u8, IntegerType::U8Type(U8Type {}), UInt8); - - Testu8::test_min(std::u8::MIN); - Testu8::test_max(std::u8::MAX); - - Testu8::test_input(); - - Testu8::test_add(); - // Testu8::test_sub(); //Todo: Catch subtraction overflow error in gadget - Testu8::test_mul(); - Testu8::test_div(); - Testu8::test_pow(); - - Testu8::test_eq(); - Testu8::test_ge(); - Testu8::test_gt(); - Testu8::test_le(); - Testu8::test_gt(); - - Testu8::test_assert_eq(); - Testu8::test_ternary(); +fn test_u8_min() { + TestU8::test_min(std::u8::MIN); +} + +#[test] +fn test_u8_max() { + TestU8::test_max(std::u8::MAX); +} + +#[test] +fn test_u8_input() { + TestU8::test_input(); +} + +#[test] +fn test_u8_add() { + TestU8::test_add(); +} + +#[test] +fn test_u8_sub() { + TestU8::test_sub(); +} + +#[test] +fn test_u8_mul() { + TestU8::test_mul(); +} + +#[test] +fn test_u8_div() { + TestU8::test_div(); +} + +#[test] +fn test_u8_pow() { + TestU8::test_pow(); +} + +#[test] +fn test_u8_eq() { + TestU8::test_eq(); +} + +#[test] +fn test_u8_ge() { + TestU8::test_ge(); +} + +#[test] +fn test_u8_gt() { + TestU8::test_gt(); +} + +#[test] +fn test_u8_le() { + TestU8::test_le(); +} + +#[test] +fn test_u8_lt() { + TestU8::test_lt(); +} + +#[test] +fn test_u8_assert_eq() { + TestU8::test_assert_eq(); +} + +#[test] +fn test_u8_ternary() { + TestU8::test_ternary(); }