-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-cardboard-prolog.scm
167 lines (134 loc) · 3.17 KB
/
test-cardboard-prolog.scm
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
(load "cardboard-prolog.scm")
(load "utils.scm")
(define database
'(
((female alice))
((male bob))
((male dan))
((female emily))
((female fran))
((child alice bob))
((child dan bob))
((child emily dan))
((son #(X) #(Y)) (male #(X)) (child #(X) #(Y)))
((daughter #(X) #(Y)) (female #(X)) (child #(X) #(Y)))
((descendant #(X) #(Y)) (child #(X) #(Y)))
((descendant #(X) #(Y)) (child #(X) #(Z)) (descendant #(Z) #(Y)))
)
)
;-----------
(test rename-term-1
(rename-term '(descendant #(X) #(Y)) 1)
'(descendant #(X 1) #(Y 1))
)
(test rename-term-2
(rename-term '(descendant #(X 1) #(Y 1)) 2)
'(descendant #(X 2) #(Y 2))
)
(test collect-vars-1
(collect-vars '(descendant (son #(X)) #(Y)) '())
'(#(Y) #(X))
)
;------------
(test unify-1
(unify '(child bob #(Y)) '(child #(X) alice) '())
'( (#(Y) alice) (#(X) bob) )
)
(test unify-2
(unify '(son #(X) zeke) '(son #(X) #(Y)) '())
'( (#(Y) zeke) )
)
(test unify-3
(unify '(son #(P) zeke) '(son #(X) #(Y)) '())
'( (#(Y) zeke) (#(P) #(X)) )
)
;------------
(test expand-1
(expand '(child #(X) #(Y)) '( (#(Y) alice) (#(X) bob) ))
'(child bob alice)
)
;------------
(test match-all-1
(match-all database '( (female alice) ))
'(()) ; list containing empty env ==> true
)
(test match-all-2
(match-all database '( (female foobar) ))
'() ; list containing no envs ==> false
)
(test match-all-3
(match-all database '( (female #(A)) ))
'(((#(A) alice)) ((#(A) emily)) ((#(A) fran)))
)
(test match-all-4
(match-all database '( (child dan bob) ))
'(())
)
(test match-all-5
(match-all database '( (child #(A) bob) ))
'(((#(A) alice)) ((#(A) dan)))
)
(test match-all-6
(match-all database '( (female #(A)) (child #(A) bob) ))
'(((#(A) alice)))
)
(test match-all-7
(match-all database '( (female #(A)) (child #(A) #(B)) ))
'(((#(B) bob) (#(A) alice)) ((#(B) dan) (#(A) emily)))
)
(test match-all-son-1
(match-all database '( (son dan bob) ))
'(())
)
(test match-all-son-2
(match-all database '( (son dan emily) ))
'()
)
(test match-all-son-3
(match-all database '( (son alice bob) ))
'()
)
(test match-all-son-3a
(match-all database '( (son #(X) bob) ))
'(((#(X) dan)))
)
(test match-all-son-3b
(match-all database '( (son #(P) bob) ))
'(((#(P) dan)))
)
(test match-all-son-4
(match-all database '( (son dan #(X)) ))
'(((#(X) bob)))
)
(test match-all-son-4a
(match-all database '( (son dan #(P)) ))
'(((#(P) bob)))
)
(test match-all-son-5
(match-all database '( (son #(X) #(Y)) ))
'(((#(Y) bob) (#(X) dan)))
)
(test match-all-son-5a
(match-all database '( (son #(P) #(Q)) ))
'(((#(Q) bob) (#(P) dan)))
)
(test match-all-descendant-1
(match-all database '( (descendant alice bob) ))
'(())
)
(test match-all-descendant-2
(match-all database '( (descendant alice emily) ))
'()
)
(test match-all-descendant-3
(match-all database '( (descendant emily bob) ))
'(())
)
(test match-all-descendant-4
(match-all database '( (descendant #(X) bob) ))
'(((#(X) alice)) ((#(X) dan)) ((#(X) emily)))
)
(test match-all-descendant-5
(match-all database '( (descendant emily #(X)) ))
'(((#(X) dan)) ((#(X) bob)))
)