Skip to content

Commit ec38c07

Browse files
committed
feat(tests): add lambda core as a test suite, to ensure it keeps working as intended
1 parent 316db97 commit ec38c07

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
(import std.Testing)
2+
3+
(let _true (fun (x)
4+
(fun (y &x) x)))
5+
(let _false (fun (x)
6+
(fun (y) y)))
7+
(let _not (fun (b)
8+
((b _false) _true)))
9+
(let _and (fun (b1)
10+
(fun (b2 &b1)
11+
((b1 b2) _false))))
12+
(let _or (fun (b1)
13+
(fun (b2 &b1)
14+
((b1 _true) b2))))
15+
16+
(let _zero (fun (f) (fun (x) x)))
17+
(let _succ (fun (n)
18+
(fun (f &n)
19+
(fun (x &n &f)
20+
(f ((n f) x))))))
21+
(let _pred (fun (n)
22+
(fun (f &n)
23+
(fun (x &n &f)
24+
(((n (fun (g &f) (fun (h &g &f) (h (g f))))) (fun (u &x) x)) (fun (a) a))))))
25+
(let _one (_succ _zero))
26+
27+
(let read_church (fun (n)
28+
((n (fun (x) (+ x 1))) 0)))
29+
(let read_bool (fun (b)
30+
((b true) false)))
31+
32+
(test:suite lambda {
33+
(test:case "logic" {
34+
(test:eq (read_bool _true) true)
35+
(test:eq (read_bool _false) false)
36+
37+
(test:case "not" {
38+
(test:eq (read_bool (_not _true)) false)
39+
(test:eq (read_bool (_not _false)) true) })
40+
41+
(test:case "and" {
42+
(test:eq (read_bool ((_and _true) _true)) true)
43+
(test:eq (read_bool ((_and _true) _false)) false)
44+
(test:eq (read_bool ((_and _false) _true)) false)
45+
(test:eq (read_bool ((_and _false) _false)) false) })
46+
47+
(test:case "or" {
48+
(test:eq (read_bool ((_or _true) _true)) true)
49+
(test:eq (read_bool ((_or _true) _false)) true)
50+
(test:eq (read_bool ((_or _false) _true)) true)
51+
(test:eq (read_bool ((_or _false) _false)) false) })})
52+
53+
(test:case "church numerals" {
54+
(test:case "zero / succ" {
55+
(test:eq (read_church _zero) 0)
56+
(test:eq (read_church _one) 1)
57+
(test:eq (read_church (_succ _one)) 2)
58+
(test:eq (read_church (_succ (_succ _one))) 3) })
59+
60+
(test:case "pred" {
61+
(test:eq (read_church (_pred _one)) 0)
62+
(test:eq (read_church (_pred (_succ _one))) 1)
63+
(test:eq (read_church (_pred (_succ (_succ _one)))) 2) })})})

tests/unittests/resources/LangSuite/unittests.ark

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
(import list-tests)
99
(import string-tests)
1010
(import async-tests)
11+
(import lambda-core-tests)
1112

1213
(import std.List)
1314

@@ -21,7 +22,8 @@
2122
macro-tests:macro-output
2223
list-tests:list-output
2324
string-tests:string-output
24-
async-tests:async-output ]))
25+
async-tests:async-output
26+
lambda-core-tests:lambda-output ]))
2527
(let success_count (list:sum (@ outputs 0)))
2628
(let failure_count (list:sum (@ outputs 1)))
2729

0 commit comments

Comments
 (0)