forked from gregr/first-order-miniKanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unify-tests.rkt
91 lines (71 loc) · 1.52 KB
/
unify-tests.rkt
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
(display "\nRunning == tests")
(newline)
(test 'equality-0
(run* (q) (== 1 1))
'((_.0)))
(test 'equality-1
(run* (q) (== 5 q))
'((5)))
(test 'equality-2
(run* (q) (== q 5))
'((5)))
(test 'equality-3
(run* (p q) (== p q))
'((_.0 _.0)))
(test 'equality-4
(run* (p q) (== (cons p 3) (cons 5 q)))
'((5 3)))
(test 'equality-5
(run* (p q r) (== p q) (== q r))
'((_.0 _.0 _.0)))
(test 'equality-6
(run* (q) (== q 'hello))
'((hello)))
(test 'equality-7
(run* (q) (== q "world"))
'(("world")))
(test 'equality-with-conde-0
(run* (q) (conde ((== 4 q)) ((== 1 q))))
'((4) (1)))
(test 'equality-with-conde-1
(run* (p q) (== 9 p) (conde ((== 7 q)) ((== 8 q))))
'((9 7) (9 8)))
(test 'equality-with-conde-2
(run* (p q r) (conde ((== p q)) ((== p r))))
'((_.0 _.0 _.1) (_.0 _.1 _.0)))
(test 'equality-fail-0
(run* (q) (== 3 90))
'())
(test 'equality-fail-1
(run* (q) (== q 41) (== q 64))
'())
(test 'equality-fail-2
(run* (q) (== 93 37) (== q 6))
'())
(test 'equality-fresh-test-0
(run* (a b) (fresh (c) (== a c) (== b c)))
'((_.0 _.0)))
(test 'equality-pair-test-0
(run* (a) (== a (cons 55 249)))
'(((55 . 249))))
(test 'equality-pair-test-1
(run* (a b c) (== c (cons a b)))
'((_.0 _.1 (_.0 . _.1))))
; Faster-miniKanren tests
(test "1"
(run 1 (q) (== 5 q))
'((5)))
(test "2"
(run* (q)
(conde
[(== 5 q)]
[(== 6 q)]))
'((5) (6)))
(test "3"
(run* (q)
(fresh (a d)
(conde
[(== 5 a)]
[(== 6 d)])
(== `(,a . ,d) q)))
'(((5 . _.0)) ((_.0 . 6))))