fix uint tests

This commit is contained in:
collin 2020-07-15 19:55:04 -07:00
parent 5ccda0750a
commit 6f36dc6cd6
6 changed files with 349 additions and 103 deletions

View File

@ -74,7 +74,10 @@ macro_rules! test_uint {
let r1: $_type = rand::random(); let r1: $_type = rand::random();
let r2: $_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::<Fq>::new(); let cs = TestConstraintSystem::<Fq>::new();
let difference_allocated = <$gadget>::alloc(cs, || Ok(difference)).unwrap(); let difference_allocated = <$gadget>::alloc(cs, || Ok(difference)).unwrap();

View File

@ -28,29 +28,80 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt128) {
_ => panic!("program output unknown return value"), _ => panic!("program output unknown return value"),
} }
} }
#[test]
#[ignore] // temporarily ignore memory expensive tests for travis
fn test_u128() {
test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128); test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128);
#[test]
fn test_u128_min() {
TestU128::test_min(std::u128::MIN); TestU128::test_min(std::u128::MIN);
}
#[test]
fn test_u128_max() {
TestU128::test_max(std::u128::MAX); TestU128::test_max(std::u128::MAX);
}
#[test]
fn test_u128_input() {
TestU128::test_input(); TestU128::test_input();
}
#[test]
fn test_u128_add() {
TestU128::test_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(); TestU128::test_mul();
}
#[test] // this test takes ~30 sec
fn test_u128_div() {
TestU128::test_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_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(); TestU128::test_assert_eq();
}
#[test]
fn test_u128_ternary() {
TestU128::test_ternary(); TestU128::test_ternary();
} }

View File

@ -29,27 +29,79 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt16) {
} }
} }
test_uint!(TestU16, u16, IntegerType::U16Type(U16Type {}), UInt16);
#[test] #[test]
fn test_u16() { fn test_u16_min() {
test_uint!(Testu16, u16, IntegerType::U16Type(U16Type {}), UInt16); TestU16::test_min(std::u16::MIN);
}
Testu16::test_min(std::u16::MIN);
Testu16::test_max(std::u16::MAX); #[test]
fn test_u16_max() {
Testu16::test_input(); TestU16::test_max(std::u16::MAX);
}
Testu16::test_add();
// Testu16::test_sub(); //Todo: Catch subtraction overflow error in gadget #[test]
Testu16::test_mul(); fn test_u16_input() {
Testu16::test_div(); TestU16::test_input();
Testu16::test_pow(); }
Testu16::test_eq(); #[test]
Testu16::test_ge(); fn test_u16_add() {
Testu16::test_gt(); TestU16::test_add();
Testu16::test_le(); }
Testu16::test_gt();
#[test]
Testu16::test_assert_eq(); fn test_u16_sub() {
Testu16::test_ternary(); 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();
} }

View File

@ -46,43 +46,79 @@ pub(crate) fn output_one(program: EdwardsTestCompiler) {
output_number(program, 1u32); output_number(program, 1u32);
} }
#[test]
fn test_u32() {
test_uint!(TestU32, u32, IntegerType::U32Type(U32Type {}), UInt32); test_uint!(TestU32, u32, IntegerType::U32Type(U32Type {}), UInt32);
#[test]
fn test_u32_min() {
TestU32::test_min(std::u32::MIN); TestU32::test_min(std::u32::MIN);
}
#[test]
fn test_u32_max() {
TestU32::test_max(std::u32::MAX); TestU32::test_max(std::u32::MAX);
}
#[test]
fn test_u32_input() {
TestU32::test_input(); TestU32::test_input();
}
#[test]
fn test_u32_add() {
TestU32::test_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(); TestU32::test_mul();
}
#[test]
fn test_u32_div() {
TestU32::test_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_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(); TestU32::test_assert_eq();
}
#[test]
fn test_u32_ternary() {
TestU32::test_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);
}

View File

@ -29,28 +29,80 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt64) {
} }
} }
test_uint!(TestU64, u64, IntegerType::U64Type(U64Type {}), UInt64);
#[test] #[test]
#[ignore] //temporarily ignore memory expensive tests for travis fn test_u64_min() {
fn test_u64() { TestU64::test_min(std::u64::MIN);
test_uint!(Testu64, u64, IntegerType::U64Type(U64Type {}), UInt64); }
Testu64::test_min(std::u64::MIN); #[test]
Testu64::test_max(std::u64::MAX); fn test_u64_max() {
TestU64::test_max(std::u64::MAX);
Testu64::test_input(); }
Testu64::test_add(); #[test]
// Testu64::test_sub(); //Todo: Catch subtraction overflow error in gadget fn test_u64_input() {
Testu64::test_mul(); TestU64::test_input();
Testu64::test_div(); }
Testu64::test_pow(); // takes ~2mins
#[test]
Testu64::test_eq(); fn test_u64_add() {
Testu64::test_ge(); TestU64::test_add();
Testu64::test_gt(); }
Testu64::test_le();
Testu64::test_gt(); #[test]
fn test_u64_sub() {
Testu64::test_assert_eq(); TestU64::test_sub();
Testu64::test_ternary(); }
#[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();
} }

View File

@ -29,27 +29,79 @@ fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt8) {
} }
} }
test_uint!(TestU8, u8, IntegerType::U8Type(U8Type {}), UInt8);
#[test] #[test]
fn test_u8() { fn test_u8_min() {
test_uint!(Testu8, u8, IntegerType::U8Type(U8Type {}), UInt8); TestU8::test_min(std::u8::MIN);
}
Testu8::test_min(std::u8::MIN);
Testu8::test_max(std::u8::MAX); #[test]
fn test_u8_max() {
Testu8::test_input(); TestU8::test_max(std::u8::MAX);
}
Testu8::test_add();
// Testu8::test_sub(); //Todo: Catch subtraction overflow error in gadget #[test]
Testu8::test_mul(); fn test_u8_input() {
Testu8::test_div(); TestU8::test_input();
Testu8::test_pow(); }
Testu8::test_eq(); #[test]
Testu8::test_ge(); fn test_u8_add() {
Testu8::test_gt(); TestU8::test_add();
Testu8::test_le(); }
Testu8::test_gt();
#[test]
Testu8::test_assert_eq(); fn test_u8_sub() {
Testu8::test_ternary(); 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();
} }