-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.alc
72 lines (65 loc) · 2.2 KB
/
test.alc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(def assert (txt a b)
(pr txt)
(if (iso a b)
(prn "\t: \x1B[92mPassed\x1B[39m")
(prn "\t: \x1B[91mFailed\x1B[39m")))
(assert "This will Pass" 1 1)
(assert "This will Fail" 1 0)
(assert "addition" 3 (+ 1 2))
(assert " (+) is 0" 0 (+ ))
(assert "cons test "
(cons 'f '(a b))
'(f a b))
(= x '(a b))
(assert "(cons 'f x) -> (f a b)"
'(f a b)
(cons 'f x))
(assert "(cons 'a nil) -> (a)"
(cons 'a nil)
'(a))
(assert "(car '(a b c)) -> a"
(car '(a b c))
'a)
(assert "(cdr '(a b c)) -> (b c)"
(cdr '(a b c))
'(b c))
(assert "(list 'a 1 "foo" '(b)) -> (a 1 "foo" (b))"
(list 'a 1 "foo" '(b))
'(a 1 "foo" (b)))
(assert "(cons 'a (cons 1 (cons "foo" (cons '(b) nil)))) -> (a 1 "foo" (b))"
(cons 'a
(cons 1
(cons "foo"
(cons
'(b) nil))))
'(a 1 "foo" (b)))
(= x '(a b))
(assert "(= (car x) 'z) -> z" (= (car x) 'z) 'z)
(assert "and x -> (z b)" x '(z b))
(def average (x y)
(/ (+ x y) 2)))
(assert "(average 2 4) -> 3" (average 2 4) 3)
(assert "((fn (x y) (/ (+ x y) 2)) 2 4) -> 3" ((fn (x y) (/ (+ x y) 2)) 2 4) 3)
(assert "(\"foo\" 0) -> #\\f" ("foo" 0) #\f)
(= s "foo")
(assert "(= (s 0) #\m) ->#\m " (= (s 0) #\m) #\m)
(assert " s -> moo" s "moo")
(assert "(let x 1 (+ x (* x 2))) -> 3" (let x 1 (+ x (* x 2))) 3)
(assert "(with (x 3 y 4)
(sqrt (+ (expt x 2) (expt y 2))))
-> 5" (with (x 3 y 4)
(sqrt (+ (expt x 2) (expt y 2)))) 5.0)
(assert "(if (odd 1) 'a 'b) -> a" (if (odd 1) 'a 'b) 'a)
(assert "(if (odd 2) 'a 'b) -> b" (if (odd 2) 'a 'b) 'b)
(def mylen (xs)
(if (no xs)
0
(+ 1 (mylen (cdr xs)))))
(assert "mylen nil -> 0" (mylen nil) 0 )
(assert "(mylen '(a b)) -> 2 " (mylen '(a b)) 2)
(assert "(is 'a 'a) -> t" (is 'a 'a) t)
(assert "(is "foo" "foo") -> t" (is "foo" "foo") t)
(assert "(let x (list 'a) (is x x)) -> t" (let x (list 'a) (is x x)) t)
(assert "(is (list 'a) (list 'a)) -> nil" (is (list 'a) (list 'a)) nil)
(assert "(iso (list 'a) (list 'a)) ->t" (iso (list 'a) (list 'a)) t)
(assert "(let x 'a (in x 'a 'b 'c)) -> t" (let x 'a (in x 'a 'b 'c)) t)