-
Notifications
You must be signed in to change notification settings - Fork 5
/
==-tests.ss
53 lines (45 loc) · 979 Bytes
/
==-tests.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
(load "mk.scm")
(test-check "1"
(run 1 (q) (== 5 q))
'(5))
(test-check "2"
(run* (q)
(conde
[(== 5 q)]
[(== 6 q)]))
'(5 6))
(test-check "3"
(run* (q)
(fresh (a d)
(conde
[(== 5 a)]
[(== 6 d)])
(== `(,a . ,d) q)))
'((5 . _.0) (_.0 . 6)))
(define appendo
(lambda (l s out)
(conde
[(== '() l) (== s out)]
[(fresh (a d res)
(== `(,a . ,d) l)
(== `(,a . ,res) out)
(appendo d s res))])))
(test-check "4"
(run* (q) (appendo '(a b c) '(d e) q))
'((a b c d e)))
(test-check "5"
(run* (q) (appendo q '(d e) '(a b c d e)))
'((a b c)))
(test-check "6"
(run* (q) (appendo '(a b c) q '(a b c d e)))
'((d e)))
(test-check "7"
(run 5 (q)
(fresh (l s out)
(appendo l s out)
(== `(,l ,s ,out) q)))
'((() _.0 _.0)
((_.0) _.1 (_.0 . _.1))
((_.0 _.1) _.2 (_.0 _.1 . _.2))
((_.0 _.1 _.2) _.3 (_.0 _.1 _.2 . _.3))
((_.0 _.1 _.2 _.3) _.4 (_.0 _.1 _.2 _.3 . _.4))))