29 lines
1.2 KiB
Clojure
29 lines
1.2 KiB
Clojure
(ns book.exchange-test
|
|
(:require [midje.sweet :refer :all]
|
|
[book.exchange :refer :all]
|
|
[book.match :refer [create-buy-book
|
|
create-sell-book]]
|
|
[clojure.core.async :refer [chan go >!! <!!]]))
|
|
|
|
(facts "the exchange as an whole"
|
|
(fact "sell order followed by a buy order trivialities "
|
|
(let [incoming-order-channel (chan)
|
|
trades-channel (chan)
|
|
new-book-order-channel (chan)
|
|
master-book {:sell (create-sell-book) :buy (create-buy-book)}]
|
|
(go (process-orders master-book incoming-order-channel trades-channel new-book-order-channel))
|
|
(>!! incoming-order-channel {:type :sell :quantity 10 :price 2})
|
|
(<!! new-book-order-channel) => {:type :sell :quantity 10 :price 2}
|
|
(>!! incoming-order-channel {:type :buy :quantity 20 :price 2})
|
|
(<!! trades-channel) => #:book.order{:book-id nil
|
|
:order-id nil
|
|
:price 2
|
|
:quantity 10
|
|
:type :sell}
|
|
(<!! new-book-order-channel) => {:type :buy :quantity 10 :price 2})))
|
|
|
|
|
|
|
|
|
|
|