Sweep-up of changes on illuminator

This commit is contained in:
Simon Brooke 2020-04-12 17:13:49 +01:00
parent f6d989135e
commit 5d37ad29eb
7 changed files with 281 additions and 102 deletions

View file

@ -79,8 +79,31 @@
(-> actual :cities :falkirk :stock :iron)
17)
"Stock should be topped up by the difference between the supply and
the demand amount."))
the demand amount."))))
)
)
(deftest run-test
(let [world (deep-merge
default-world
{:cities
{:aberdeen
{:stock {:fish 5}
:supplies {:fish 12}
:prices {:fish 1.1}}
:falkirk
{:stock {:iron 10}
:demands {:iron 5}
:supplies {:iron 12}
:prices {:iron 1.1}}}})
actual (run world)]
(is
(=
(-> actual :cities :aberdeen :stock :fish)
(+ (-> world :cities :aberdeen :supplies :fish)
(-> world :cities :aberdeen :stock :fish)))
"If stock is not empty and price is above cost, stock should be topped up by supply amount.")
(is
(=
(-> actual :cities :falkirk :stock :iron)
17)
"Stock should be topped up by the difference between the supply and
the demand amount.")))

View file

@ -22,3 +22,106 @@
expected 1.7] ;;
(is (= actual expected) "if information select the most recent")))))
(deftest burden-test
(testing "Burden of merchant"
(let [world (deep-merge
default-world
{:merchants
{:archie
{:stock
{:iron 1}}
:belinda
{:stock
{:fish 2}}
:callum
{:stock
{:iron 1
:fish 1}}}})]
(let [actual (burden :archie world)
expected (-> world :commodities :iron :weight)]
(is (= actual expected)))
(let [actual (burden :belinda world)
expected (* 2 (-> world :commodities :fish :weight))]
(is (= actual expected)))
(let [actual (burden :callum world)
expected (+
(-> world :commodities :iron :weight)
(-> world :commodities :fish :weight))]
(is (= actual expected)))
(let [actual (burden {} world)
expected 0]
(is (= actual expected)))
(let [actual (burden (-> world :merchants :deidre) world)
expected 0]
(is (= actual expected))))))
(deftest can-carry-test
(testing "What merchants can carry"
(let [world (deep-merge
default-world
{:merchants
{:archie
{:cash 5
:stock
{:iron 1}}
:belinda
{:stock
{:fish 2}}
:callum
{:stock
{:iron 1
:fish 1}}}})]
(let [actual (can-carry :archie world :fish)
expected 0]
(is (= actual expected)))
(let [actual (can-carry :belinda world :fish)
expected 8]
(is (= actual expected)))
(let [actual (can-carry (-> world :merchants :archie) world :fish)
expected 0]
(is (= actual expected)))
(let [actual (can-carry {:stock {:fish 7} :capacity 10} world :fish)
expected 3]
(is (= actual expected))))))
(deftest affordability-test
(testing "What merchants can afford to purchase"
(let [world (deep-merge
default-world
{:merchants
{:archie
{:cash 5
:stock
{:iron 1}}
:belinda
{:stock
{:fish 2}}
:callum
{:stock
{:iron 1
:fish 1}}}})]
(let [actual (can-afford :archie world :fish)
expected 5]
(is (= actual expected)))
(let [actual (can-afford :belinda world :fish)
expected 100]
(is (= actual expected)))
(let [actual (can-afford (-> world :merchants :archie) world :fish)
expected 5]
(is (= actual expected)))
(let [actual (can-afford {:cash 3 :location :buckie} world :fish)
expected 3]
(is (= actual expected)))
(is (thrown-with-msg?
Exception
#"No merchant?"
(can-afford :no-one world :fish)))
(is (thrown-with-msg?
Exception
#"No known location for merchant.*"
(can-afford {:cash 3} world :fish))))))
(deftest add-stock-test
(let [actual (add-stock {:iron 2 :fish 5} {:fish 3 :whisky 7})
expected {:iron 2 :fish 8 :whisky 7}]))