This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlist.arc.t
85 lines (68 loc) · 1.71 KB
/
dlist.arc.t
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
(test-iso "dlist creates a doubly linked list containing given elems"
'(3 4 5)
(dl-elems:dlist '(3 4 5)))
(= d (dlist))
(test-ok "dl-empty? works"
(dl-empty? d))
(push-front d 3)
(test-iso "push-front on empty list works"
'(3)
dl-elems.d)
(test-iso "pop-back works on single-elem dlist"
3
(pop-back d))
(test-ok "dl-empty? works"
(dl-empty? d))
(test-nil "pop-back on empty dlist works"
(pop-back d))
(push-back d 3)
(test-iso "push-back on empty list works"
'(3)
dl-elems.d)
(test-iso "what's pushed from back can be popped from front"
3
(pop-front d))
(test-ok "dl-empty? works"
(dl-empty? d))
(= d (dlist '(5)))
(push-front d 4)
(push-front d 3)
(push-back d 6)
(push-front d 2)
(test-iso "series of pop-backs works"
'(6 5 4 3 2)
(accum acc
(until (dl-empty? d)
(acc (pop-back d)))))
(= d (dlist '(5)))
(push-front d 4)
(push-front d 3)
(push-back d 6)
(push-front d 2)
(test-iso "series of pop-fronts works"
'(2 3 4 5 6)
(accum acc
(until (dl-empty? d)
(acc (pop-front d)))))
(= d (dlist '(45)))
(pushn d 44 3)
(test-iso "pushn works"
'(44 45)
dl-elems.d)
(test-nil "pushn returns nil when nothing is popped"
(pushn d 43 3))
(test-is "pushn returns popped elem when it exists"
45
(pushn d 42 3))
(test-iso "pushn pops element"
'(42 43 44)
dl-elems.d)
(test-iso "serialize dlist works"
'(dlist (42 43 44))
(serialize (dlist '(42 43 44))))
(test-iso "serialize handles tables containing dlists"
'(table ((3 (dlist (4))) (1 2)))
(serialize (obj 1 2 3 (dlist '(4)))))
(test-iso "unserialize undoes serialize for dlists"
(dlist '(42 43 44))
(unserialize:serialize (dlist '(42 43 44))))