Use midje for testing
This commit is contained in:
1 parent
c099924a89
commit
516cccf4cd
5 files changed
+161
-122
No files matched your search
@@ -1,52 +1,53 @@
|
||||
(ns book.test-PersistentSortedList
|
||||
(:require [clojure.test :refer :all]
|
||||
(:require [midje.sweet :refer :all]
|
||||
[book.util :refer [sorted-list sorted-list-by]]))
|
||||
|
||||
|
||||
|
||||
(deftest test-match-buy-order-in-sell-book
|
||||
(testing "constructing"
|
||||
(is (empty? (map nil? (sorted-list)))))
|
||||
(facts "test-match-buy-order-in-sell-book"
|
||||
(fact "constructing"
|
||||
(map nil? (sorted-list)) => empty?)
|
||||
;; The following are tests that fails...
|
||||
;(is (empty? (vec (sorted-list)))))
|
||||
(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 (empty? (rest (sorted-list))))
|
||||
(is (= (str (type (rest (sorted-list)))) "class book.PersistentSortedList")))
|
||||
(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]))))
|
||||
;(vec (sorted-list)) => empty?)
|
||||
(fact "Test ordering."
|
||||
(sorted-list 1 2 3) => (sorted-list 3 2 1)
|
||||
(sorted-list 1 2 2 3) => (sorted-list 3 2 1 2))
|
||||
(fact "count"
|
||||
(count (sorted-list)) => 0
|
||||
(count (sorted-list 1 2 3)) => 3
|
||||
(count (sorted-list 1 2 3 2)) => 4)
|
||||
(fact "rest"
|
||||
(rest (sorted-list 1 2 3)) => (sorted-list 2 3)
|
||||
(rest (sorted-list 1 2 3 2)) => (sorted-list 2 2 3)
|
||||
(rest (sorted-list 1)) => (sorted-list)
|
||||
(rest (sorted-list)) => empty?
|
||||
(str (type (rest (sorted-list)))) => "class book.PersistentSortedList")
|
||||
(fact "next"
|
||||
(next (sorted-list 1 2 3)) => (sorted-list 2 3)
|
||||
(next (sorted-list 1 2 3 2)) => (sorted-list 2 2 3)
|
||||
(next (sorted-list 1)) => nil
|
||||
(next (sorted-list)) => nil)
|
||||
(fact "drop"
|
||||
(drop 2 (sorted-list 1 2 3)) => (sorted-list 3)
|
||||
(drop 3 (sorted-list 1 2 3)) => (list))
|
||||
(fact "reduce"
|
||||
(reduce + (sorted-list 1 2 3)) => 6
|
||||
(reduce + 10 (sorted-list 1 2 3)) => 16)
|
||||
(fact "peek/pop"
|
||||
(peek (sorted-list 1 2 3)) => 1
|
||||
(peek (sorted-list 1 1 1 2 3)) => 1
|
||||
(peek (sorted-list)) => nil
|
||||
(pop (sorted-list 1 2 3)) => (sorted-list 2 3)
|
||||
(pop (sorted-list 1 1 2 3)) => (sorted-list 1 2 3)
|
||||
(pop (sorted-list 1 1 1 2 3)) => (sorted-list 1 1 2 3)
|
||||
(pop (sorted-list)) => (throws IllegalStateException))
|
||||
|
||||
(fact "count after change"
|
||||
(let [l (sorted-list 1 2 3)]
|
||||
(count (conj l 4)) => 4
|
||||
(count (conj l 3)) => 4
|
||||
(count (cons 3 l)) => 4
|
||||
(count (rest l)) => 2
|
||||
(count (pop l)) => 2))
|
||||
(fact "sorted-list-by"
|
||||
(sorted-list-by > 1 2 3) => [3 2 1]))
|
||||
Reference in new issue
Block a user