Sell book works!
This commit is contained in:
1 parent
0d126be10c
commit
1fa719ffe3
6 files changed
+239
-9
No files matched your search
@@ -0,0 +1,47 @@
|
||||
(ns book.test-PersistentSortedList
|
||||
(:require [clojure.test :refer :all]
|
||||
[book.core :refer [sorted-list sorted-list-by]]))
|
||||
|
||||
|
||||
|
||||
(deftest test-match-buy-order-in-sell-book
|
||||
(testing "Test ordering."
|
||||
(is (= (sorted-list 1 2 3) (sorted-list 3 2 1)))
|
||||
(is (= (sorted-list 1 2 2 3) (sorted-list 3 2 1 2))))
|
||||
(testing "count"
|
||||
(is (= (count (sorted-list)) 0))
|
||||
(is (= (count (sorted-list 1 2 3)) 3))
|
||||
(is (= (count (sorted-list 1 2 3 2)) 4)))
|
||||
(testing "rest"
|
||||
(is (= (rest (sorted-list 1 2 3)) (sorted-list 2 3)))
|
||||
(is (= (rest (sorted-list 1 2 3 2)) (sorted-list 2 2 3)))
|
||||
(is (= (rest (sorted-list 1)) (list)))
|
||||
(is (= (rest (sorted-list)) (list))))
|
||||
(testing "next"
|
||||
(is (= (next (sorted-list 1 2 3)) (sorted-list 2 3)))
|
||||
(is (= (next (sorted-list 1 2 3 2)) (sorted-list 2 2 3)))
|
||||
(is (= (next (sorted-list 1)) nil))
|
||||
(is (= (next (sorted-list)) nil)))
|
||||
(testing "drop"
|
||||
(is (= (drop 2 (sorted-list 1 2 3)) (sorted-list 3)))
|
||||
(is (= (drop 3 (sorted-list 1 2 3)) (list))))
|
||||
(testing "reduce"
|
||||
(is (= (reduce + (sorted-list 1 2 3)) 6))
|
||||
(is (= (reduce + 10 (sorted-list 1 2 3)) 16)))
|
||||
(testing "peek/pop"
|
||||
(is (= (peek (sorted-list 1 2 3)) 1))
|
||||
(is (= (peek (sorted-list 1 1 1 2 3)) 1))
|
||||
(is (= (peek (sorted-list)) nil))
|
||||
(is (= (pop (sorted-list 1 2 3)) (sorted-list 2 3)))
|
||||
(is (= (pop (sorted-list 1 1 2 3)) (sorted-list 1 2 3)))
|
||||
(is (= (pop (sorted-list 1 1 1 2 3)) (sorted-list 1 1 2 3)))
|
||||
(is (thrown? IllegalStateException (pop (sorted-list)) nil)))
|
||||
(testing "count after change"
|
||||
(let [l (sorted-list 1 2 3)]
|
||||
(is (= (count (conj l 4)) 4))
|
||||
(is (= (count (conj l 3)) 4))
|
||||
(is (= (count (cons 3 l)) 4))
|
||||
(is (= (count (rest l)) 2))
|
||||
(is (= (count (pop l)) 2))))
|
||||
(testing "sorted-list-by"
|
||||
(is (= (sorted-list-by > 1 2 3) [3 2 1]))))
|
||||
Reference in new issue
Block a user