(ns book.core-test (:require [clojure.test :refer :all] [book.core :refer :all])) (deftest test-match-buy-order-in-sell-book (testing "Simplest case." (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)] (is (= new-book [])) (is (= trades [#:book.order{:quantity 10 :price 2 :book-id 101 :order-id 102 :type :sell}])))) (testing "Simplest case II." (let [sell-book (create-book {:type :sell :quantity 10 :price 2 :book.order/id 103}) order {:type :buy :quantity 10 :price 3 :book.order/id 104} [trades new-book] (match-buy-order-in-sell-book sell-book order)] (is (= new-book [])) (is (= trades [#:book.order{:quantity 10 :price 2 :book-id 103 :order-id 104 :type :sell}])))) (testing "Simplest case III." (let [sell-book (create-book {:type :sell :quantity 10 :price 2 :book.order/id 105}) order {:type :buy :quantity 8 :price 2 :book.order/id 106} [trades new-book] (match-buy-order-in-sell-book sell-book order)] (is (= new-book [{:type :sell :quantity 2 :price 2 :book.order/id 105}])) (is (= trades [#:book.order{:quantity 8 :price 2 :book-id 105 :order-id 106 :type :sell}])))) (testing "Simplest case IV." (let [sell-book (create-book {:type :sell :quantity 2 :price 12 :book.order/id 107} {:type :sell :quantity 8 :price 13 :book.order/id 108}) order {:type :buy :quantity 10 :price 13 :book.order/id 109} [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}])))))