blob: c004d3f64db4c5b14fd18935ef38d79209d143fe (
plain)
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
|
(let [{: contains
: flip
: head
: keys
: slice
: tail
} (require :lib.table)
{: describe
: test-end} (require :lib.test)]
(describe "# TABLE" (fn []
(describe "contains()" (fn [t]
(t {:given "a list and an element it contains"
:should "returns true"
:expected true
:actual (contains [:apple :orange :pear] :apple)})
(t {:given "a list and an element it does not contain"
:should "returns false"
:expected false
:actual (contains [:apple :orange :pear] :gorilla)})))
(describe "flip()" (fn [t]
(let [input {:apple "red" :banana "yellow"}
expected {:red "apple" :yellow "banana"} ]
(t {:given "a table"
:should "flip that table!"
: expected
:actual (flip input)}))))
(describe "head()" (fn [t]
(t {:given "a list of elements"
:should "returns the first element of a list"
:expected :apple
:actual (head [:apple :orange :pear])})
(t {:given "an empty list"
:should "returns an empty list"
:expected 0
:actual (length (head []))})))
(describe "keys()" (fn [t]
(let [input {:apple :red :banana :yellow}
actual (keys input)
sorted (table.sort actual) ;; SIDE EFFECT!!
]
(t {:given "a table"
:should "returns a list of keys"
:expected [:apple :banana]
: actual}))))
(describe "slice()" (fn [t]
(t (let [t [:apple :orange :pear :banana :strawberry] ]
{:given "a list of elements and a start"
:should "return the list starting at start"
:expected [:orange :pear :banana :strawberry]
:actual (slice t 2)}))
(t (let [t [:apple :orange :pear :banana :strawberry] ]
{:given "a list of elements and a start and a stop"
:should "return the items between the two"
:expected [:orange :pear]
:actual (slice t 2 3)}))))
(describe "tail()" (fn [t]
(t {:given "a list"
:should "return it minus the head"
:expected [:apple :pear]
:actual (tail [:orange :apple :pear])
})
(t {:given "a single item list"
:should "return empty list"
:expected []
:actual (tail [:orange])
})
(t {:given "an empty list"
:should "return empty list"
:expected []
:actual (tail [])
})))
(test-end))))
|