add checked neg check in tests

This commit is contained in:
collin 2020-07-16 21:26:39 -07:00
parent 2607204b79
commit dbaa334eb6
2 changed files with 33 additions and 28 deletions

View File

@ -1,3 +1,4 @@
function main(a: i8, b: i8) -> i8 {
print!("{} - {}", a, b);
return a - b
}

View File

@ -1,9 +1,9 @@
macro_rules! test_int {
($name: ident, $_type: ty, $integer_type: expr, $gadget: ty) => {
($name: ident, $type_: ty, $integer_type: expr, $gadget: ty) => {
pub struct $name {}
impl $name {
fn test_min(min: $_type) {
fn test_min(min: $type_) {
let min_allocated = <$gadget>::constant(min);
let bytes = include_bytes!("min.leo");
@ -12,7 +12,7 @@ macro_rules! test_int {
output_expected_allocated(program, min_allocated);
}
fn test_max(max: $_type) {
fn test_max(max: $type_) {
let max_allocated = <$gadget>::constant(max);
let bytes = include_bytes!("max.leo");
@ -25,7 +25,7 @@ macro_rules! test_int {
impl IntegerTester for $name {
fn test_input() {
// valid input
let num: $_type = rand::random();
let num: $type_ = rand::random();
let expected = <$gadget>::constant(num);
let bytes = include_bytes!("input.leo");
@ -49,8 +49,8 @@ macro_rules! test_int {
fn test_add() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r2: $_type = rand::random();
let r1: $type_ = rand::random();
let r2: $type_ = rand::random();
let sum = match r1.checked_add(r2) {
Some(valid) => valid,
@ -74,8 +74,12 @@ macro_rules! test_int {
fn test_sub() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r2: $_type = rand::random();
let r1: $type_ = rand::random();
let r2: $type_ = rand::random();
if r2.checked_neg().is_none() {
continue;
}
let difference = match r1.checked_sub(r2) {
Some(valid) => valid,
@ -99,8 +103,8 @@ macro_rules! test_int {
fn test_mul() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r2: $_type = rand::random();
let r1: $type_ = rand::random();
let r2: $type_ = rand::random();
let product = match r1.checked_mul(r2) {
Some(valid) => valid,
@ -124,8 +128,8 @@ macro_rules! test_int {
fn test_div() {
// for _ in 0..10 {// these loops take an excessive amount of time
let r1: $_type = rand::random();
let r2: $_type = rand::random();
let r1: $type_ = rand::random();
let r2: $type_ = rand::random();
let bytes = include_bytes!("div.leo");
let mut program = parse_program(bytes).unwrap();
@ -154,8 +158,8 @@ macro_rules! test_int {
fn test_pow() {
// for _ in 0..10 {// these loops take an excessive amount of time
let r1: $_type = rand::random();
let r2: $_type = rand::random();
let r1: $type_ = rand::random();
let r2: $type_ = rand::random();
let r2 = r2 as u32; // we cast to u32 here because of rust pow() requirements
let result = match r1.checked_pow(r2) {
@ -180,7 +184,7 @@ macro_rules! test_int {
fn test_eq() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r1: $type_ = rand::random();
// test equal
let bytes = include_bytes!("eq.leo");
@ -194,7 +198,7 @@ macro_rules! test_int {
output_true(program);
// test not equal
let r2: $_type = rand::random();
let r2: $type_ = rand::random();
let result = r1.eq(&r2);
@ -211,7 +215,7 @@ macro_rules! test_int {
fn test_ge() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r1: $type_ = rand::random();
// test equal
let bytes = include_bytes!("ge.leo");
@ -225,7 +229,7 @@ macro_rules! test_int {
output_true(program);
// test not equal
let r2: $_type = rand::random();
let r2: $type_ = rand::random();
let result = r1.ge(&r2);
@ -242,7 +246,7 @@ macro_rules! test_int {
fn test_gt() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r1: $type_ = rand::random();
// test equal
let bytes = include_bytes!("gt.leo");
@ -256,7 +260,7 @@ macro_rules! test_int {
output_false(program);
// test not equal
let r2: $_type = rand::random();
let r2: $type_ = rand::random();
let result = r1.gt(&r2);
@ -273,7 +277,7 @@ macro_rules! test_int {
fn test_le() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r1: $type_ = rand::random();
// test equal
let bytes = include_bytes!("le.leo");
@ -287,7 +291,7 @@ macro_rules! test_int {
output_true(program);
// test not equal
let r2: $_type = rand::random();
let r2: $type_ = rand::random();
let result = r1.le(&r2);
@ -304,7 +308,7 @@ macro_rules! test_int {
fn test_lt() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r1: $type_ = rand::random();
// test equal
let bytes = include_bytes!("lt.leo");
@ -318,7 +322,7 @@ macro_rules! test_int {
output_false(program);
// test not equal
let r2: $_type = rand::random();
let r2: $type_ = rand::random();
let result = r1.lt(&r2);
@ -335,7 +339,7 @@ macro_rules! test_int {
fn test_assert_eq() {
for _ in 0..10 {
let r1: $_type = rand::random();
let r1: $type_ = rand::random();
// test equal
let bytes = include_bytes!("assert_eq.leo");
@ -349,7 +353,7 @@ macro_rules! test_int {
let _ = get_output(program);
// test not equal
let r2: $_type = rand::random();
let r2: $type_ = rand::random();
if r1 == r2 {
continue;
@ -369,8 +373,8 @@ macro_rules! test_int {
}
fn test_ternary() {
let r1: $_type = rand::random();
let r2: $_type = rand::random();
let r1: $type_ = rand::random();
let r2: $type_ = rand::random();
let g1 = <$gadget>::constant(r1);
let g2 = <$gadget>::constant(r2);