Adjustment of prices and quantities in markets
This commit is contained in:
parent
fcf8a8fa0d
commit
530760ee02
10 changed files with 186 additions and 10 deletions
86
test/the_great_game/merchants/markets_test.clj
Normal file
86
test/the_great_game/merchants/markets_test.clj
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
(ns the-great-game.merchants.markets-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[the-great-game.utils :refer [deep-merge]]
|
||||
[the-great-game.world.world :refer [default-world]]
|
||||
[the-great-game.merchants.markets :refer :all]))
|
||||
|
||||
|
||||
(deftest new-price-test
|
||||
(testing "Adjustment of prices based on supply and demand"
|
||||
(is (> (new-price 1 0 10 10) 1)
|
||||
"If no stock but there is supply and demand, price should rise")
|
||||
(is (> (new-price 1 0 0 10) 1)
|
||||
"If no stock but there is demand, price should rise")
|
||||
(is (> (new-price 1 5 0 10) 1)
|
||||
"If there is insufficient stock to meet demand, price should rise")
|
||||
(is (= (new-price 1 10 0 10) 1)
|
||||
"If there is exactly sufficient stock to meet demand, price should not change")
|
||||
(is (< (new-price 1 10 0 5) 1)
|
||||
"If there is surplus stock beyond demand, price should fall")
|
||||
(is (> (new-price 1 0 0 10) (new-price 1 5 0 10))
|
||||
"The greater the relative undersupply, the more prices should rise")
|
||||
(is (< (new-price 1 10 0 0)(new-price 1 10 0 5) 1)
|
||||
"The greater the relative oversupply, the more prices should fall")
|
||||
))
|
||||
|
||||
(deftest adjust-qunatity-and-price-test
|
||||
(testing "Adjustment in quantity and price: supply only."
|
||||
(let [world (deep-merge
|
||||
default-world
|
||||
{:cities
|
||||
{:falkirk
|
||||
{:stock {:iron 0}
|
||||
:supplies {:iron 12}}}})
|
||||
actual (adjust-quantity-and-price world :falkirk :iron)]
|
||||
(is
|
||||
(=
|
||||
(-> actual :cities :falkirk :stock :iron)
|
||||
(-> world :cities :falkirk :supplies :iron))
|
||||
"If stock is empty it should be topped up by supply amount."))
|
||||
(let [world (deep-merge
|
||||
default-world
|
||||
{:cities
|
||||
{:falkirk
|
||||
{:stock {:iron 5}
|
||||
:supplies {:iron 12}
|
||||
:prices {:iron 0.9}}}})
|
||||
actual (adjust-quantity-and-price world :falkirk :iron)]
|
||||
(is
|
||||
(=
|
||||
(-> actual :cities :falkirk :stock :iron)
|
||||
(-> world :cities :falkirk :supplies :iron))
|
||||
"If stock is not empty and price is below cost, stock should be topped up only to supply amount."))
|
||||
(let [world (deep-merge
|
||||
default-world
|
||||
{:cities
|
||||
{:falkirk
|
||||
{:stock {:iron 5}
|
||||
:supplies {:iron 12}
|
||||
:prices {:iron 1.1}}}})
|
||||
actual (adjust-quantity-and-price world :falkirk :iron)]
|
||||
(is
|
||||
(=
|
||||
(-> actual :cities :falkirk :stock :iron)
|
||||
(+ (-> world :cities :falkirk :supplies :iron)
|
||||
(-> world :cities :falkirk :stock :iron)))
|
||||
"If stock is not empty and price is above cost, stock should be topped up by supply amount.")))
|
||||
(testing "Adjustment in quantity and price: supply and demand."
|
||||
(let [world (deep-merge
|
||||
default-world
|
||||
{:cities
|
||||
{:falkirk
|
||||
{:stock {:iron 10}
|
||||
:demands {:iron 5}
|
||||
:supplies {:iron 12}
|
||||
:prices {:iron 1.1}}}})
|
||||
actual (adjust-quantity-and-price world :falkirk :iron)]
|
||||
(is
|
||||
(=
|
||||
(-> actual :cities :falkirk :stock :iron)
|
||||
17)
|
||||
"Stock should be topped up by the difference between the supply and
|
||||
the demand amount."))
|
||||
|
||||
)
|
||||
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue