Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katat committed Sep 21, 2024
1 parent bff8d27 commit 1b027e8
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/fixture/asm/kimchi/generic_nested_func.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@ noname.0.7.0

DoubleGeneric<1>
DoubleGeneric<1>
DoubleGeneric<1>
DoubleGeneric<1>
DoubleGeneric<1,-1>
DoubleGeneric<1,-1>
DoubleGeneric<1,-1>
(0,0) -> (4,0)
(1,0) -> (5,0)
(2,0) -> (6,0)
(3,0) -> (4,1) -> (5,1) -> (6,1)
13 changes: 13 additions & 0 deletions examples/fixture/asm/kimchi/generic_nested_method.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@ noname.0.7.0

DoubleGeneric<1>
DoubleGeneric<1>
DoubleGeneric<1>
DoubleGeneric<1>
DoubleGeneric<1,-1>
DoubleGeneric<1,-1>
DoubleGeneric<1,-1>
(0,0) -> (4,0)
(1,0) -> (5,0)
(2,0) -> (6,0)
(3,0) -> (4,1) -> (5,1) -> (6,1)
5 changes: 5 additions & 0 deletions examples/fixture/asm/r1cs/generic_nested_func.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ noname.0.7.0

v_4 == (v_1) * (1)
v_4 == (v_2) * (1)
v_4 == (v_3) * (1)
5 changes: 5 additions & 0 deletions examples/fixture/asm/r1cs/generic_nested_method.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ noname.0.7.0

v_4 == (v_1) * (1)
v_4 == (v_2) * (1)
v_4 == (v_3) * (1)
17 changes: 17 additions & 0 deletions examples/generic_nested_func.no
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn nested_func(const LEN: Field) -> [Field; LEN] {
return [0; LEN];
}

fn mod_arr(val: Field) -> [Field; 3] {
// this generic function should be instantiated
let mut result = nested_func(3);
for idx in 0..3 {
result[idx] = val;
}
return result;
}

fn main(pub val: Field) -> [Field; 3] {
let result = mod_arr(val);
return result;
}
21 changes: 21 additions & 0 deletions examples/generic_nested_method.no
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
struct Thing {
xx: Field,
}

fn Thing.nested_func(const LEN: Field) -> [Field; LEN] {
return [0; LEN];
}

fn Thing.mod_arr(self) -> [Field; 3] {
// this generic function should be instantiated
let mut result = self.nested_func(3);
for idx in 0..3 {
result[idx] = self.xx;
}
return result;
}

fn main(pub val: Field) -> [Field; 3] {
let thing = Thing {xx: val};
return thing.mod_arr();
}
36 changes: 36 additions & 0 deletions src/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,39 @@ fn test_generic_iterator(#[case] backend: BackendKind) -> miette::Result<()> {

Ok(())
}

#[rstest]
#[case::kimchi_vesta(BackendKind::KimchiVesta(KimchiVesta::new(false)))]
#[case::r1cs(BackendKind::R1csBls12_381(R1CS::new()))]
fn test_generic_nested_func(#[case] backend: BackendKind) -> miette::Result<()> {
let public_inputs = r#"{"val":"1"}"#;
let private_inputs = r#"{}"#;

test_file(
"generic_nested_func",
public_inputs,
private_inputs,
vec!["1", "1", "1"],
backend,
)?;

Ok(())
}

#[rstest]
#[case::kimchi_vesta(BackendKind::KimchiVesta(KimchiVesta::new(false)))]
#[case::r1cs(BackendKind::R1csBls12_381(R1CS::new()))]
fn test_generic_nested_method(#[case] backend: BackendKind) -> miette::Result<()> {
let public_inputs = r#"{"val":"1"}"#;
let private_inputs = r#"{}"#;

test_file(
"generic_nested_method",
public_inputs,
private_inputs,
vec!["1", "1", "1"],
backend,
)?;

Ok(())
}

0 comments on commit 1b027e8

Please sign in to comment.