Sell book works!
This commit is contained in:
1 parent
0d126be10c
commit
1fa719ffe3
6 files changed
+239
-9
No files matched your search
+45
-4
@@ -3,10 +3,8 @@
|
||||
[book.core :refer :all]))
|
||||
|
||||
|
||||
|
||||
|
||||
(deftest test-match-buy-order-in-sell-book
|
||||
(testing "Simplest case."
|
||||
(testing "Simplest case I."
|
||||
(let [sell-book (create-book {:type :sell :quantity 10 :price 2 :book.order/id 101})
|
||||
order {:type :buy :quantity 10 :price 2 :book.order/id 102}
|
||||
[trades new-book] (match-buy-order-in-sell-book sell-book order)]
|
||||
@@ -33,4 +31,47 @@
|
||||
[trades new-book] (match-buy-order-in-sell-book sell-book order)]
|
||||
(is (= new-book []))
|
||||
(is (= trades [#:book.order{:quantity 2 :price 12 :book-id 107 :order-id 109 :type :sell}
|
||||
#:book.order{:quantity 8 :price 13 :book-id 108 :order-id 109 :type :sell}])))))
|
||||
#:book.order{:quantity 8 :price 13 :book-id 108 :order-id 109 :type :sell}]))))
|
||||
|
||||
(testing "Simplest case V."
|
||||
(let [sell-book (create-book {:type :sell :quantity 2 :price 12 :book.order/id 110} {:type :sell :quantity 8 :price 13 :book.order/id 111})
|
||||
order {:type :buy :quantity 10 :price 13 :book.order/id 112}
|
||||
[trades new-book] (match-buy-order-in-sell-book sell-book order)]
|
||||
(is (empty? new-book))
|
||||
(is (= trades [#:book.order{:quantity 2 :price 12 :book-id 110 :order-id 112 :type :sell}
|
||||
#:book.order{:quantity 8 :price 13 :book-id 111 :order-id 112 :type :sell}]))))
|
||||
|
||||
(testing "Simplest case VI."
|
||||
(let [sell-book (create-book {:type :sell :quantity 2 :price 12 :book.order/id 113} {:type :sell :quantity 8 :price 13 :book.order/id 114})
|
||||
order {:type :buy :quantity 9 :price 13 :book.order/id 115}
|
||||
[trades new-book] (match-buy-order-in-sell-book sell-book order)]
|
||||
(is (= new-book (create-book {:type :sell :quantity 1 :price 13 :book.order/id 114})))
|
||||
(is (= trades [#:book.order{:quantity 2 :price 12 :book-id 113 :order-id 115 :type :sell}
|
||||
#:book.order{:quantity 7 :price 13 :book-id 114 :order-id 115 :type :sell}]))))
|
||||
|
||||
(testing "Simplest case VII."
|
||||
(let [sell-book (create-book {:type :sell :quantity 2 :price 12 :book.order/id 116} {:type :sell :quantity 8 :price 13 :book.order/id 117})
|
||||
order {:type :buy :quantity 21 :price 13 :book.order/id 118}
|
||||
[trades new-book leftover-order] (match-buy-order-in-sell-book sell-book order)]
|
||||
(is (empty? new-book))
|
||||
(is (= trades [#:book.order{:quantity 2 :price 12 :book-id 116 :order-id 118 :type :sell}
|
||||
#:book.order{:quantity 8 :price 13 :book-id 117 :order-id 118 :type :sell}]))
|
||||
(is (= leftover-order {:type :buy :quantity 11 :price 13 :book.order/id 118}))))
|
||||
|
||||
(testing "Simplest case IIX."
|
||||
(let [sell-book (create-book {:type :sell :quantity 2 :price 12 :book.order/id 116} {:type :sell :quantity 8 :price 13 :book.order/id 117})
|
||||
order {:type :buy :quantity 21 :price 10 :book.order/id 118}
|
||||
[trades new-book leftover-order] (match-buy-order-in-sell-book sell-book order)]
|
||||
(is (= new-book sell-book))
|
||||
(is (= trades []))
|
||||
(is (= leftover-order order)))))
|
||||
|
||||
|
||||
;
|
||||
;(deftest test-match-sell-order-in-buy-book
|
||||
; (testing "Simplest case I."
|
||||
; (let [sell-book (create-book {:type :sell :quantity 10 :price 2 :book.order/id 101})
|
||||
; order {:type :buy :quantity 10 :price 2 :book.order/id 102}
|
||||
; [trades new-book] (match-sell-order-in-buy-book sell-book order)]
|
||||
; (is (= new-book []))
|
||||
; (is (= trades [#:book.order{:quantity 10 :price 2 :book-id 101 :order-id 102 :type :sell}])))))
|
||||
Reference in new issue
Block a user