Skip to content

Commit 782be33

Browse files
Adds more tests
1 parent fe8f008 commit 782be33

12 files changed

+81
-0
lines changed

tests/test-hm-ackermann.cl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Test: Ackermann function - deeply nested recursion
2+
# Should infer (int, int) -> int
3+
4+
def ackermann(m, n):
5+
if m == 0:
6+
return n + 1
7+
else:
8+
if n == 0:
9+
return ackermann(m - 1, 1)
10+
else:
11+
return ackermann(m - 1, ackermann(m, n - 1))
12+
13+
type(ackermann(2, 2))
14+
print(ackermann(2, 2))

tests/test-hm-ackermann.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int
2+
7

tests/test-hm-double-recurse.cl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test: Function that makes two recursive calls with different args
2+
# Should infer int -> int
3+
4+
def double_recurse(n):
5+
if n <= 0:
6+
return 1
7+
else:
8+
return double_recurse(n - 1) + double_recurse(n - 2)
9+
10+
type(double_recurse(5))
11+
print(double_recurse(5))

tests/test-hm-double-recurse.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int
2+
13

tests/test-hm-factorial-acc.cl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test: Factorial with accumulator - tests multiple params in recursion
2+
# Should infer (int, int) -> int
3+
4+
def fact_acc(n, acc):
5+
if n <= 1:
6+
return acc
7+
else:
8+
return fact_acc(n - 1, n * acc)
9+
10+
type(fact_acc(5, 1))
11+
print(fact_acc(5, 1))

tests/test-hm-factorial-acc.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int
2+
120

tests/test-hm-is-positive.cl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test: Recursive check that eventually returns bool
2+
# Should infer int -> bool
3+
4+
def all_positive(n):
5+
if n <= 0:
6+
return n == 0
7+
else:
8+
return all_positive(n - 1)
9+
10+
type(all_positive(5))
11+
print(all_positive(5))

tests/test-hm-is-positive.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bool
2+
1

tests/test-hm-nested-arg.cl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test: Recursive call used as argument to another call
2+
# Should infer int -> int
3+
4+
def nested(n):
5+
if n <= 1:
6+
return n
7+
else:
8+
return nested(nested(n - 1))
9+
10+
type(nested(5))
11+
print(nested(5))

tests/test-hm-nested-arg.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int
2+
1

0 commit comments

Comments
 (0)