Skip to content

Commit

Permalink
Add tests for augmented assignments
Browse files Browse the repository at this point in the history
for +=, -=, *=
  • Loading branch information
bufferhe4d committed Nov 11, 2024
1 parent df2247f commit fc9041d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/assignment.no
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main(pub xx: Field) {
};

// ideally: thing.xx += 1;
thing.xx = thing.xx + 1;
thing.xx += 1;

try_to_mutate(thing);

Expand Down
16 changes: 16 additions & 0 deletions examples/augmented_assign.no
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn main(pub xx: Field, yy: Field) -> Field {
let mut zz = xx + yy;
let mut zz2 = xx + yy;

zz += 1;
zz2 = zz2 + 1;

zz *= zz;
zz2 = zz2 * zz2;

zz -= yy;
zz2 = zz2 - yy;
assert_eq(zz, zz2);

return zz;
}
7 changes: 7 additions & 0 deletions examples/fixture/asm/r1cs/augmented_assign.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ noname.0.7.0
@ public inputs: 2

v_4 == (v_2 + v_3 + 1) * (v_2 + v_3 + 1)
v_5 == (v_2 + v_3 + 1) * (v_2 + v_3 + 1)
-1 * v_3 + v_5 == (-1 * v_3 + v_4) * (1)
-1 * v_3 + v_4 == (v_1) * (1)
19 changes: 19 additions & 0 deletions src/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,25 @@ fn test_assignment(#[case] backend: BackendKind) -> miette::Result<()> {
Ok(())
}

#[rstest]
#[case::kimchi_vesta(BackendKind::KimchiVesta(KimchiVesta::new(false)))]
#[case::r1cs(BackendKind::R1csBls12_381(R1CS::new()))]
fn test_augmented_assign(#[case] backend: BackendKind) -> miette::Result<()> {
let private_inputs = r#"{"yy": "2"}"#;
let public_inputs = r#"{"xx": "3"}"#;
let expected_public_output = vec!["34"];

test_file(
"augmented_assign",
public_inputs,
private_inputs,
expected_public_output,
backend,
)?;

Ok(())
}

#[rstest]
#[case::kimchi_vesta(BackendKind::KimchiVesta(KimchiVesta::new(false)))]
#[case::r1cs(BackendKind::R1csBls12_381(R1CS::new()))]
Expand Down

0 comments on commit fc9041d

Please sign in to comment.