-
Notifications
You must be signed in to change notification settings - Fork 0
/
kanren-test.ss
82 lines (64 loc) · 2.24 KB
/
kanren-test.ss
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
(import :kanren)
(import :kanren-test-utils)
(test-equal? "test function success" 1 1)
(test-equal? "test function fail" 1 2)
(test-equal? "Lookup success"
(lookup (var 1) (list (cons (var 1) 1)))
1)
(test-equal? "Lookup fail"
(lookup (var 1) (list (cons (var 0) 1)))
#f)
(test-equal? "Lookup empty"
(lookup (var 1) '())
#f)
(test-equal? "walk around nowhere"
(walk (var 1) '())
(var 1))
(test-equal? "walk around somewhere"
(walk (var 0) (list (cons (var 0) 1)))
1)
(test-equal? "walk into var"
(walk (var 0) (list (cons (var 0) (var 2))))
(var 2))
(test-equal? "walk with prims"
(walk 1 '(list (cons 1 2)))
1)
(test-equal? "is var"
(var? (var 1))
#t)
(test-equal? "is not var"
(var? 1)
#f)
;; (test-equal? "cmp var, not var"
;; (var=? (var 0) 1)
;; #f)
(test-equal? "extends assocs"
(ext-assocs (var 0) 1 '())
(list (cons (var 0) 1)))
(test-equal? "unify vars"
(unify (var 0) (var 1) '())
(list (cons (var 0) (var 1))))
(test-equal? "unify with empty assocs-list"
(unify (var 0) 1 '())
(list (cons (var 0) 1)))
(test-equal? "== success"
((== (var 1) 1) state0)
(list (cons 0 (list (cons (var 1) 1)))))
(test-equal? "fresh success"
(let ((r (fresh (lambda (a) (== a 1)))))
(run* state0 r))
(list (cons 1 (list (cons (var 0) 1)))))
(test-equal? "conj success"
(let ((r (fresh (lambda (a)
(fresh (lambda (b)
(conj (== a 1)
(== a b))))))))
(run* state0 r))
(list (cons 2 (list (cons (var 1) 1) (cons (var 0) 1)))))
(test-equal? "disj success"
(let ((r (fresh (lambda (a)
(disj (== a 1)
(== a 2))))))
(run* state0 r))
(list (cons 1 (list (cons (var 0) 1)))
(cons 1 (list (cons (var 0) 2)))))