Add tests in the language
This commit is contained in:
parent
74bd9c9582
commit
e8d8731922
6 changed files with 102 additions and 0 deletions
22
test_all.sh
Executable file
22
test_all.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
echo '== Building CLI =='
|
||||||
|
cd cli
|
||||||
|
go build .
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
|
||||||
|
echo '== Testing anglais =='
|
||||||
|
|
||||||
|
for file in ./tests/*.ang; do
|
||||||
|
echo "-- Test-running file $file --"
|
||||||
|
|
||||||
|
if ! ./cli/cli run "$file"; then
|
||||||
|
echo "-- Error --"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "-- Success --"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo '== Successfully ran all tests =='
|
||||||
5
tests/arithmetics.ang
Normal file
5
tests/arithmetics.ang
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
assert(1+1 == 2)
|
||||||
|
assert(3*2 == 6)
|
||||||
|
assert(3/4 == 0.75)
|
||||||
|
assert(2 - 5 == -3)
|
||||||
|
|
||||||
11
tests/conditions.ang
Normal file
11
tests/conditions.ang
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Basic equality
|
||||||
|
assert(1 == 1)
|
||||||
|
assert(0 == 0)
|
||||||
|
assert("" == "")
|
||||||
|
|
||||||
|
assert([] == [])
|
||||||
|
assert([3, 1, 4, 1] == [3, 1, 4, 1])
|
||||||
|
assert([true, 1024, nil, "Hello world!"] == [true, 1024, nil, "Hello world!"])
|
||||||
|
|
||||||
|
# Inequality
|
||||||
|
assert(2 != 3)
|
||||||
24
tests/list.ang
Normal file
24
tests/list.ang
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
list := []
|
||||||
|
|
||||||
|
x := 1
|
||||||
|
while x <= 1000 {
|
||||||
|
list = list.append(x)
|
||||||
|
assert(list.reduce(func(tot, a){
|
||||||
|
return tot + a
|
||||||
|
}, 0) == x*(x + 1)/2)
|
||||||
|
|
||||||
|
x = x + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func sum(a, b) {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
list = []
|
||||||
|
x = 1
|
||||||
|
while x <= 100 {
|
||||||
|
list = list.append(2*x - 1)
|
||||||
|
assert(list.reduce(sum, 0) == x*x)
|
||||||
|
|
||||||
|
x = x + 1
|
||||||
|
}
|
||||||
28
tests/recursive_fib.ang
Normal file
28
tests/recursive_fib.ang
Normal 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
|
||||||
|
}
|
||||||
12
tests/simple_func.ang
Normal file
12
tests/simple_func.ang
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
func sum(a, b) {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
breakpoint
|
||||||
|
|
||||||
|
assert(sum(1, 2) == 3)
|
||||||
|
breakpoint
|
||||||
|
|
||||||
|
assert(sum(3, 3) == 6)
|
||||||
|
breakpoint
|
||||||
Loading…
Add table
Add a link
Reference in a new issue