2020-06-06 02:51:26 +03:00
|
|
|
use crate::{
|
|
|
|
boolean::{output_expected_boolean, output_false, output_true},
|
2020-06-14 03:43:59 +03:00
|
|
|
get_error,
|
2020-06-08 09:30:39 +03:00
|
|
|
get_output,
|
2020-06-21 01:24:46 +03:00
|
|
|
integers::{fail_integer, IntegerTester},
|
2020-06-09 05:13:47 +03:00
|
|
|
parse_program,
|
2020-06-08 09:30:39 +03:00
|
|
|
EdwardsConstrainedValue,
|
|
|
|
EdwardsTestCompiler,
|
2020-06-06 02:51:26 +03:00
|
|
|
};
|
2020-06-26 00:27:19 +03:00
|
|
|
use leo_compiler::{ConstrainedValue, Integer};
|
2020-06-11 03:53:38 +03:00
|
|
|
use leo_inputs::types::{IntegerType, U128Type};
|
2020-06-26 00:27:19 +03:00
|
|
|
use leo_types::InputValue;
|
2020-06-06 02:51:26 +03:00
|
|
|
|
|
|
|
use snarkos_curves::edwards_bls12::Fq;
|
2020-06-08 09:30:39 +03:00
|
|
|
use snarkos_models::gadgets::{
|
|
|
|
r1cs::TestConstraintSystem,
|
|
|
|
utilities::{alloc::AllocGadget, uint::UInt128},
|
|
|
|
};
|
2020-06-06 02:51:26 +03:00
|
|
|
|
|
|
|
fn output_expected_allocated(program: EdwardsTestCompiler, expected: UInt128) {
|
|
|
|
let output = get_output(program);
|
|
|
|
|
|
|
|
match output {
|
|
|
|
EdwardsConstrainedValue::Return(vec) => match vec.as_slice() {
|
|
|
|
[ConstrainedValue::Integer(Integer::U128(actual))] => assert_eq!(*actual, expected),
|
|
|
|
_ => panic!("program output unknown return value"),
|
|
|
|
},
|
|
|
|
_ => panic!("program output unknown return value"),
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 05:55:04 +03:00
|
|
|
test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128);
|
2020-06-06 02:51:26 +03:00
|
|
|
|
|
|
|
#[test]
|
2020-07-16 05:55:04 +03:00
|
|
|
fn test_u128_min() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_min(std::u128::MIN);
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_max() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_max(std::u128::MAX);
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
2020-06-06 02:51:26 +03:00
|
|
|
|
2020-07-16 05:55:04 +03:00
|
|
|
#[test]
|
|
|
|
fn test_u128_input() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_input();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
2020-06-06 02:51:26 +03:00
|
|
|
|
2020-07-16 05:55:04 +03:00
|
|
|
#[test]
|
|
|
|
fn test_u128_add() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_add();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_sub() {
|
|
|
|
TestU128::test_sub();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test] // this test take ~1 min
|
|
|
|
fn test_u128_mul() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_mul();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test] // this test takes ~30 sec
|
|
|
|
fn test_u128_div() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_div();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore] // this test takes ~10 mins
|
|
|
|
fn test_u128_pow() {
|
|
|
|
TestU128::test_pow();
|
|
|
|
}
|
2020-06-06 02:51:26 +03:00
|
|
|
|
2020-07-16 05:55:04 +03:00
|
|
|
#[test]
|
|
|
|
fn test_u128_eq() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_eq();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_ge() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_ge();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_gt() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_gt();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_le() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_le();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_lt() {
|
|
|
|
TestU128::test_lt();
|
|
|
|
}
|
2020-06-06 02:51:26 +03:00
|
|
|
|
2020-07-16 05:55:04 +03:00
|
|
|
#[test]
|
|
|
|
fn test_u128_assert_eq() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_assert_eq();
|
2020-07-16 05:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_u128_ternary() {
|
2020-06-06 02:51:26 +03:00
|
|
|
TestU128::test_ternary();
|
|
|
|
}
|