mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
add tests for i types
This commit is contained in:
parent
2f39ecdbc3
commit
fe2f29ccad
3
compiler/tests/integers/i128/add.leo
Normal file
3
compiler/tests/integers/i128/add.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> i128 {
|
||||
return a + b
|
||||
}
|
3
compiler/tests/integers/i128/assert_eq.leo
Normal file
3
compiler/tests/integers/i128/assert_eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) {
|
||||
assert_eq!(a, b);
|
||||
}
|
3
compiler/tests/integers/i128/div.leo
Normal file
3
compiler/tests/integers/i128/div.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> i128 {
|
||||
return a / b
|
||||
}
|
3
compiler/tests/integers/i128/eq.leo
Normal file
3
compiler/tests/integers/i128/eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> bool {
|
||||
return a == b
|
||||
}
|
3
compiler/tests/integers/i128/ge.leo
Normal file
3
compiler/tests/integers/i128/ge.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> bool {
|
||||
return a >= b
|
||||
}
|
3
compiler/tests/integers/i128/gt.leo
Normal file
3
compiler/tests/integers/i128/gt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> bool {
|
||||
return a > b
|
||||
}
|
3
compiler/tests/integers/i128/input.leo
Normal file
3
compiler/tests/integers/i128/input.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(x: i128) -> i128 {
|
||||
return x
|
||||
}
|
3
compiler/tests/integers/i128/le.leo
Normal file
3
compiler/tests/integers/i128/le.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> bool {
|
||||
return a <= b
|
||||
}
|
3
compiler/tests/integers/i128/lt.leo
Normal file
3
compiler/tests/integers/i128/lt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> bool {
|
||||
return a < b
|
||||
}
|
3
compiler/tests/integers/i128/max.leo
Normal file
3
compiler/tests/integers/i128/max.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i128 {
|
||||
return 170141183460469231731687303715884105727
|
||||
}
|
3
compiler/tests/integers/i128/min.leo
Normal file
3
compiler/tests/integers/i128/min.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i128 {
|
||||
return -170141183460469231731687303715884105728
|
||||
}
|
106
compiler/tests/integers/i128/mod.rs
Normal file
106
compiler/tests/integers/i128/mod.rs
Normal 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();
|
||||
}
|
3
compiler/tests/integers/i128/mul.leo
Normal file
3
compiler/tests/integers/i128/mul.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> i128 {
|
||||
return a * b
|
||||
}
|
3
compiler/tests/integers/i128/one.leo
Normal file
3
compiler/tests/integers/i128/one.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i128 {
|
||||
return 1
|
||||
}
|
3
compiler/tests/integers/i128/pow.leo
Normal file
3
compiler/tests/integers/i128/pow.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> i128 {
|
||||
return a ** b
|
||||
}
|
3
compiler/tests/integers/i128/sub.leo
Normal file
3
compiler/tests/integers/i128/sub.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i128, b: i128) -> i128 {
|
||||
return a - b
|
||||
}
|
3
compiler/tests/integers/i128/ternary.leo
Normal file
3
compiler/tests/integers/i128/ternary.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(b: bool, x: i128, y: i128) -> i128 {
|
||||
return if b ? x : y
|
||||
}
|
3
compiler/tests/integers/i128/zero.leo
Normal file
3
compiler/tests/integers/i128/zero.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i128 {
|
||||
return 0
|
||||
}
|
3
compiler/tests/integers/i16/add.leo
Normal file
3
compiler/tests/integers/i16/add.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> i16 {
|
||||
return a + b
|
||||
}
|
3
compiler/tests/integers/i16/assert_eq.leo
Normal file
3
compiler/tests/integers/i16/assert_eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) {
|
||||
assert_eq!(a, b);
|
||||
}
|
3
compiler/tests/integers/i16/div.leo
Normal file
3
compiler/tests/integers/i16/div.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> i16 {
|
||||
return a / b
|
||||
}
|
3
compiler/tests/integers/i16/eq.leo
Normal file
3
compiler/tests/integers/i16/eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> bool {
|
||||
return a == b
|
||||
}
|
3
compiler/tests/integers/i16/ge.leo
Normal file
3
compiler/tests/integers/i16/ge.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> bool {
|
||||
return a >= b
|
||||
}
|
3
compiler/tests/integers/i16/gt.leo
Normal file
3
compiler/tests/integers/i16/gt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> bool {
|
||||
return a > b
|
||||
}
|
3
compiler/tests/integers/i16/input.leo
Normal file
3
compiler/tests/integers/i16/input.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(x: i16) -> i16 {
|
||||
return x
|
||||
}
|
3
compiler/tests/integers/i16/le.leo
Normal file
3
compiler/tests/integers/i16/le.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> bool {
|
||||
return a <= b
|
||||
}
|
3
compiler/tests/integers/i16/lt.leo
Normal file
3
compiler/tests/integers/i16/lt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> bool {
|
||||
return a < b
|
||||
}
|
3
compiler/tests/integers/i16/max.leo
Normal file
3
compiler/tests/integers/i16/max.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i16 {
|
||||
return 32767
|
||||
}
|
3
compiler/tests/integers/i16/min.leo
Normal file
3
compiler/tests/integers/i16/min.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i16 {
|
||||
return -32768
|
||||
}
|
105
compiler/tests/integers/i16/mod.rs
Normal file
105
compiler/tests/integers/i16/mod.rs
Normal 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();
|
||||
}
|
3
compiler/tests/integers/i16/mul.leo
Normal file
3
compiler/tests/integers/i16/mul.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> i16 {
|
||||
return a * b
|
||||
}
|
3
compiler/tests/integers/i16/one.leo
Normal file
3
compiler/tests/integers/i16/one.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i16 {
|
||||
return 1
|
||||
}
|
3
compiler/tests/integers/i16/pow.leo
Normal file
3
compiler/tests/integers/i16/pow.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> i16 {
|
||||
return a ** b
|
||||
}
|
3
compiler/tests/integers/i16/sub.leo
Normal file
3
compiler/tests/integers/i16/sub.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i16, b: i16) -> i16 {
|
||||
return a - b
|
||||
}
|
3
compiler/tests/integers/i16/ternary.leo
Normal file
3
compiler/tests/integers/i16/ternary.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(b: bool, x: i16, y: i16) -> i16 {
|
||||
return if b ? x : y
|
||||
}
|
3
compiler/tests/integers/i16/zero.leo
Normal file
3
compiler/tests/integers/i16/zero.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i16 {
|
||||
return 0
|
||||
}
|
3
compiler/tests/integers/i32/add.leo
Normal file
3
compiler/tests/integers/i32/add.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> i32 {
|
||||
return a + b
|
||||
}
|
3
compiler/tests/integers/i32/assert_eq.leo
Normal file
3
compiler/tests/integers/i32/assert_eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) {
|
||||
assert_eq!(a, b);
|
||||
}
|
3
compiler/tests/integers/i32/div.leo
Normal file
3
compiler/tests/integers/i32/div.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> i32 {
|
||||
return a / b
|
||||
}
|
3
compiler/tests/integers/i32/eq.leo
Normal file
3
compiler/tests/integers/i32/eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> bool {
|
||||
return a == b
|
||||
}
|
3
compiler/tests/integers/i32/ge.leo
Normal file
3
compiler/tests/integers/i32/ge.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> bool {
|
||||
return a >= b
|
||||
}
|
3
compiler/tests/integers/i32/gt.leo
Normal file
3
compiler/tests/integers/i32/gt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> bool {
|
||||
return a > b
|
||||
}
|
3
compiler/tests/integers/i32/input.leo
Normal file
3
compiler/tests/integers/i32/input.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(x: i32) -> i32 {
|
||||
return x
|
||||
}
|
3
compiler/tests/integers/i32/le.leo
Normal file
3
compiler/tests/integers/i32/le.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> bool {
|
||||
return a <= b
|
||||
}
|
3
compiler/tests/integers/i32/lt.leo
Normal file
3
compiler/tests/integers/i32/lt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> bool {
|
||||
return a < b
|
||||
}
|
3
compiler/tests/integers/i32/max.leo
Normal file
3
compiler/tests/integers/i32/max.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i32 {
|
||||
return 2147483647
|
||||
}
|
3
compiler/tests/integers/i32/min.leo
Normal file
3
compiler/tests/integers/i32/min.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i32 {
|
||||
return -2147483648
|
||||
}
|
105
compiler/tests/integers/i32/mod.rs
Normal file
105
compiler/tests/integers/i32/mod.rs
Normal 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();
|
||||
}
|
3
compiler/tests/integers/i32/mul.leo
Normal file
3
compiler/tests/integers/i32/mul.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> i32 {
|
||||
return a * b
|
||||
}
|
3
compiler/tests/integers/i32/one.leo
Normal file
3
compiler/tests/integers/i32/one.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i32 {
|
||||
return 1
|
||||
}
|
3
compiler/tests/integers/i32/pow.leo
Normal file
3
compiler/tests/integers/i32/pow.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> i32 {
|
||||
return a ** b
|
||||
}
|
3
compiler/tests/integers/i32/sub.leo
Normal file
3
compiler/tests/integers/i32/sub.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i32, b: i32) -> i32 {
|
||||
return a - b
|
||||
}
|
3
compiler/tests/integers/i32/ternary.leo
Normal file
3
compiler/tests/integers/i32/ternary.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(b: bool, x: i32, y: i32) -> i32 {
|
||||
return if b ? x : y
|
||||
}
|
3
compiler/tests/integers/i32/zero.leo
Normal file
3
compiler/tests/integers/i32/zero.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i32 {
|
||||
return 0
|
||||
}
|
3
compiler/tests/integers/i64/add.leo
Normal file
3
compiler/tests/integers/i64/add.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> i64 {
|
||||
return a + b
|
||||
}
|
3
compiler/tests/integers/i64/assert_eq.leo
Normal file
3
compiler/tests/integers/i64/assert_eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) {
|
||||
assert_eq!(a, b);
|
||||
}
|
3
compiler/tests/integers/i64/div.leo
Normal file
3
compiler/tests/integers/i64/div.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> i64 {
|
||||
return a / b
|
||||
}
|
3
compiler/tests/integers/i64/eq.leo
Normal file
3
compiler/tests/integers/i64/eq.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> bool {
|
||||
return a == b
|
||||
}
|
3
compiler/tests/integers/i64/ge.leo
Normal file
3
compiler/tests/integers/i64/ge.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> bool {
|
||||
return a >= b
|
||||
}
|
3
compiler/tests/integers/i64/gt.leo
Normal file
3
compiler/tests/integers/i64/gt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> bool {
|
||||
return a > b
|
||||
}
|
3
compiler/tests/integers/i64/input.leo
Normal file
3
compiler/tests/integers/i64/input.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(x: i64) -> i64 {
|
||||
return x
|
||||
}
|
3
compiler/tests/integers/i64/le.leo
Normal file
3
compiler/tests/integers/i64/le.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> bool {
|
||||
return a <= b
|
||||
}
|
3
compiler/tests/integers/i64/lt.leo
Normal file
3
compiler/tests/integers/i64/lt.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> bool {
|
||||
return a < b
|
||||
}
|
3
compiler/tests/integers/i64/max.leo
Normal file
3
compiler/tests/integers/i64/max.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i64 {
|
||||
return 9223372036854775807
|
||||
}
|
3
compiler/tests/integers/i64/min.leo
Normal file
3
compiler/tests/integers/i64/min.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i64 {
|
||||
return -9223372036854775808
|
||||
}
|
106
compiler/tests/integers/i64/mod.rs
Normal file
106
compiler/tests/integers/i64/mod.rs
Normal 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();
|
||||
}
|
3
compiler/tests/integers/i64/mul.leo
Normal file
3
compiler/tests/integers/i64/mul.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> i64 {
|
||||
return a * b
|
||||
}
|
3
compiler/tests/integers/i64/one.leo
Normal file
3
compiler/tests/integers/i64/one.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i64 {
|
||||
return 1
|
||||
}
|
3
compiler/tests/integers/i64/pow.leo
Normal file
3
compiler/tests/integers/i64/pow.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> i64 {
|
||||
return a ** b
|
||||
}
|
3
compiler/tests/integers/i64/sub.leo
Normal file
3
compiler/tests/integers/i64/sub.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(a: i64, b: i64) -> i64 {
|
||||
return a - b
|
||||
}
|
3
compiler/tests/integers/i64/ternary.leo
Normal file
3
compiler/tests/integers/i64/ternary.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(b: bool, x: i64, y: i64) -> i64 {
|
||||
return if b ? x : y
|
||||
}
|
3
compiler/tests/integers/i64/zero.leo
Normal file
3
compiler/tests/integers/i64/zero.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() -> i64 {
|
||||
return 0
|
||||
}
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user