summaryrefslogtreecommitdiff
path: root/test/main.lali
blob: a63cef7819ae80e89308c2a0b66d81759dc13186 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(set 'success t)

(defun test (test-expr res)
  (newline)
  (princ
   (list (fill ((diff (eval test-expr) res) '+)
               ('f 'fail))
         '--> test-expr))
  (and success
       (set 'success (fill ((diff (eval test-expr) res) t)
                           (f f)))))

;; atom
(test '(atom ()) f)
(test '(atom 'a) t)
(test '(atom '(x . a)) f)
(test '(atom '(x a)) f)
;(test '(atom 'a) undef)

;; diff
(test '(diff 'a ()) t)
(test '(diff () 'b) t)
(test '(diff () ()) f)
(test '(diff 'a 'b) t)
(test '(diff 'a 'a) f)
(test '(diff 'a '(b c)) t)
(test '(diff '(a b) '(b c)) t)
(test '(diff '(b . c) '(b . c)) f)
(test '(diff '(b c) '(b c)) f)

;; car
(test '(car ()) ())
(test '(car '(a)) 'a)
(test '(car '(a . b)) 'a)
(test '(car '(a b)) 'a)
(test '(car '((a . b) . c)) '(a . b))
;(test '(car 'a) undef)

;; cdr
(test '(cdr ()) ())
(test '(cdr '(a)) ())
(test '(cdr '(a . b)) 'b)
(test '(cdr '(a b)) '(b))
(test '(cdr '((a . b) . c)) 'c)
;(test '(cdr 'a) undef)

;; cons
(test '(cons 'a ()) '(a))
(test '(cons 'a 'b) '(a . b))
(test '(cons 'a '(b)) '(a b))
(test '(cons '(a . b) 'c) '((a . b) . c))

;; or
(test '(or () 'a) ())
(test '(or t 'a) t)
(test '(or 'a 'b 'c) 'a)
(test '(or f f t) t)
(test '(or t (car 'a)) t)
;(test '(or (car 'a) t) undef)

;; and
(test '(and () 'a) 'a)
(test '(and f 'a) f)
(test '(and 'a 'b 'c) 'c)
(test '(and t t f) f)
(test '(and f (car 'a)) f)
;(test '(and (car 'a) f) undef)

;; cond
(test '(cond (() 'a) (f 'b)) 'a)
(test '(cond (t 'a) (f 'b)) 'a)
(test '(cond (f 'a) (t 'b) (t 'c)) 'b)
(test '(cond (f 'a) (t 'b)) 'b)
(test '(cond (f (car 'a)) (t 'b)) 'b)
;(test '(cond (f 'a) (t (car 'a))) undef)
(test '(cond (f 'a) (f 'b)) n)

;; fill
(test '(fill (() 'a) (f 'b)) 'b)
(test '(fill (f 'a) (t 'b)) 'a)
(test '(fill (t 'a) (f 'b) (f 'c)) 'b)
(test '(fill (t 'a) (f 'b)) 'b)
(test '(fill (t (car 'a)) (f 'b)) 'b)
;(test '(fill (t 'a) (f (car 'a))) undef)
(test '(fill (t 'a) (t 'b)) n)

;; final message
(and success (prog
                (newline)
                (princ '(All with success.))
                (newline)))