From ac3fdd896dfff5b350d21e8874b2a676043ffb7c Mon Sep 17 00:00:00 2001 From: Empa Date: Sat, 6 Jan 2024 13:46:43 +0100 Subject: [PATCH] Test fib loop variant --- .../res/tests/fib_loop/fib_loop.out | 1 + .../res/tests/fib_loop/fib_loop.saf | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 crates/saft-tests/res/tests/fib_loop/fib_loop.out create mode 100644 crates/saft-tests/res/tests/fib_loop/fib_loop.saf diff --git a/crates/saft-tests/res/tests/fib_loop/fib_loop.out b/crates/saft-tests/res/tests/fib_loop/fib_loop.out new file mode 100644 index 0000000..63a38c8 --- /dev/null +++ b/crates/saft-tests/res/tests/fib_loop/fib_loop.out @@ -0,0 +1 @@ +3736710778780434371 diff --git a/crates/saft-tests/res/tests/fib_loop/fib_loop.saf b/crates/saft-tests/res/tests/fib_loop/fib_loop.saf new file mode 100644 index 0000000..0bafca4 --- /dev/null +++ b/crates/saft-tests/res/tests/fib_loop/fib_loop.saf @@ -0,0 +1,20 @@ +fn fib(n) { + if n == 0 { return 0; }; + + a := 0; + b := 1; + + loop { + if n == 1 { + break b; + }; + + c := a + b; + a = b; + b = c; + + n = n - 1; + } +} + +print(fib(100));