diff --git a/test_programs/execution_success/loop/Nargo.toml b/test_programs/execution_success/loop/Nargo.toml new file mode 100644 index 00000000000..66c72338363 --- /dev/null +++ b/test_programs/execution_success/loop/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "loop" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/loop/Prover.toml b/test_programs/execution_success/loop/Prover.toml new file mode 100644 index 00000000000..22cd5b7c12f --- /dev/null +++ b/test_programs/execution_success/loop/Prover.toml @@ -0,0 +1 @@ +sum = "6" diff --git a/test_programs/execution_success/loop/src/main.nr b/test_programs/execution_success/loop/src/main.nr new file mode 100644 index 00000000000..22fc99c7b03 --- /dev/null +++ b/test_programs/execution_success/loop/src/main.nr @@ -0,0 +1,23 @@ +// Tests a very simple program. +// +// The features being tested is basic looping. +fn main(six_as_u32: u32) { + assert_eq(loop(4), six_as_u32); + assert_eq(loop_incl(3), six_as_u32); +} + +fn loop(x: u32) -> u32 { + let mut sum = 0; + for i in 0..x { + sum = sum + i; + } + sum +} + +fn loop_incl(x: u32) -> u32 { + let mut sum = 0; + for i in 0..=x { + sum = sum + i; + } + sum +} \ No newline at end of file