From fc9041dfd395cb15f40caaa96e66a941be61aada Mon Sep 17 00:00:00 2001 From: Abdullah Talayhan Date: Mon, 11 Nov 2024 13:35:04 +0100 Subject: [PATCH] Add tests for augmented assignments for +=, -=, *= --- examples/assignment.no | 2 +- examples/augmented_assign.no | 16 ++++++++++++++++ .../fixture/asm/r1cs/augmented_assign.asm | 7 +++++++ src/tests/examples.rs | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 examples/augmented_assign.no create mode 100644 examples/fixture/asm/r1cs/augmented_assign.asm diff --git a/examples/assignment.no b/examples/assignment.no index 20d8ae4e7..b82be55cc 100644 --- a/examples/assignment.no +++ b/examples/assignment.no @@ -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); diff --git a/examples/augmented_assign.no b/examples/augmented_assign.no new file mode 100644 index 000000000..3d8a001c8 --- /dev/null +++ b/examples/augmented_assign.no @@ -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; +} diff --git a/examples/fixture/asm/r1cs/augmented_assign.asm b/examples/fixture/asm/r1cs/augmented_assign.asm new file mode 100644 index 000000000..a003c39a7 --- /dev/null +++ b/examples/fixture/asm/r1cs/augmented_assign.asm @@ -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) diff --git a/src/tests/examples.rs b/src/tests/examples.rs index 79fe56ed8..6682df3ea 100644 --- a/src/tests/examples.rs +++ b/src/tests/examples.rs @@ -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()))]