81 lines
2.4 KiB
Plaintext
81 lines
2.4 KiB
Plaintext
|
(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))))
|