Skip to content

Commit

Permalink
fix: split conditional_regression tests (noir-lang#2774)
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic authored and Sakapoi committed Oct 19, 2023
1 parent 7862a83 commit b1f4f9b
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 156 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "conditional_3_regression"
name = "conditional_regression_421"
type = "bin"
authors = [""]
compiler_version = "0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
c=[2, 4, 3, 0, ]
a=0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main(a: u32, mut c: [u32; 4]){
//Issue reported in #421
if a == c[0] {
assert(c[0] == 0);
} else {
if a == c[1] {
assert(c[1] == 0);
} else {
if a == c[2] {
assert(c[2] == 0);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "conditional_regression_547"
type = "bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn main() -> pub Field {
// Regression test for issue #547
// Warning: it must be kept at the start of main
let arr: [u8; 2] = [1, 2];
if arr[0] != arr[1] {
for i in 0..1 {
assert(i != 2);
}
}

// Regression for predicate simplification
safe_inverse(0)
}

fn safe_inverse(n: Field) -> Field
{
if n == 0 {
0
}
else {
1 / n
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "conditional_regression_579"
type = "bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
fn main(){
//Regression for Issue #579
let result1_true = test(true);
assert(result1_true.array_param[0] == 1);
let result1_false = test(false);
assert(result1_false.array_param[0] == 0);
}

struct MyStruct579 {
array_param: [u32; 2]
}

impl MyStruct579 {
fn new(array_param: [u32; 2]) -> MyStruct579 {
MyStruct579 {
array_param: array_param
}
}
}

fn test(flag: bool) -> MyStruct579 {
let mut my_struct = MyStruct579::new([0; 2]);

if flag == true {
my_struct= MyStruct579::new([1; 2]);
}
my_struct
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "conditional_regression_661"
type = "bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
fn main(a: u32, mut c: [u32; 4]){
// Regression for issue #661:
let mut c_661 :[u32;1]=[0];
if a > 5 {
c_661 = issue_661_foo(issue_661_bar(c), a);
} else {
c_661 = issue_661_foo(issue_661_bar(c), a + 2);
}
assert(c_661[0] < 20000);
}

fn test5(a : u32) {
if a > 1 {
let q = a / 2;
assert(q == 2);
}
}


fn issue_661_foo(array: [u32;4], b:u32) ->[u32;1] {
[array[0]+b]
}

fn issue_661_bar(a : [u32;4]) ->[u32;4] {
let mut b:[u32;4] = [0;4];
b[0]=a[0]+1;
b
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "conditional_regression_short_circuit"
type = "bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
c=[2, 4, 3, 0, ]
a=0
x = [104, 101, 108, 108, 111]

result = [
0x2c,
0xf2,
0x4d,
0xba,
0x5f,
0xb0,
0xa3,
0x0e,
0x26,
0xe8,
0x3b,
0x2a,
0xc5,
0xb9,
0xe2,
0x9e,
0x1b,
0x16,
0x1e,
0x5c,
0x1f,
0xa7,
0x42,
0x5e,
0x73,
0x04,
0x33,
0x62,
0x93,
0x8b,
0x98,
0x24,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use dep::std;

fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]){
//regression for short-circuit2
if 35 == a {
assert(false);
}
bar(a as Field);

if a == 3 {
c = test4();
}
assert(c[1] != 2);
call_intrinsic(x, result);
}



fn foo() {
let mut x = 1;
x /= 0;
}

fn bar(x:Field) {
if x == 15 {
foo();
}
}


fn call_intrinsic(x: [u8; 5], result: [u8; 32]) {
let mut digest = std::hash::sha256(x);
digest[0] = 5 as u8;
digest = std::hash::sha256(x);
assert(digest == result);
}

fn test4() -> [u32; 4] {
let b: [u32; 4] = [1,2,3,4];
b
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "cconditional_regression_to_bits"
type = "bin"
authors = [""]
compiler_version = "0.1"

[dependencies]
Empty file.
Loading

0 comments on commit b1f4f9b

Please sign in to comment.