Add tests in the language

This commit is contained in:
Neemek 2025-03-10 16:24:56 +01:00
parent 74bd9c9582
commit e8d8731922
Signed by: neemek
GPG key ID: 28360A8951CD0E9B
6 changed files with 102 additions and 0 deletions

28
tests/recursive_fib.ang Normal file
View file

@ -0,0 +1,28 @@
fibonacci_numbers := [
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657,
46368, 75025, 121393, 196418, 317811, 514229, 832040,
1346269, 2178309, 3524578, 5702887, 9227465, 14930352,
24157817, 39088169, 63245986, 102334155
]
func fib(n) {
if n < 2 {
return n
}
return fib(n-1) + fib(n-2)
}
x := 0
while x < fibonacci_numbers.length() {
n := fib(x)
print("assert ")
print(n)
print(" == ")
write(fibonacci_numbers.at(x))
assert(n == fibonacci_numbers.at(x))
x = x + 1
}