Merchant route selection: very basic stuff works

Tests pass.
This commit is contained in:
Simon Brooke 2019-05-13 21:46:43 +01:00
parent a7f90fa60f
commit 5619b9c1e5
15 changed files with 694 additions and 299 deletions

View file

@ -0,0 +1,23 @@
(ns the-great-game.merchants.merchants-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.merchants :refer :all]))
(deftest expected-price-test
(testing "Anticipated prices in markets"
(let [world (deep-merge
default-world
{:merchants
{:archie
{:known-prices
{:buckie
{:iron
[{:price 1.7 :date 1}
{:price 2 :date 0}]}}}}})]
(let [actual (expected-price (-> world :merchants :archie) :fish :edinburgh)
expected 1] ;;
(is (= actual expected) "if no information assume 1"))
(let [actual (expected-price (-> world :merchants :archie) :iron :buckie)
expected 1.7] ;;
(is (= actual expected) "if information select the most recent")))))

View file

@ -0,0 +1,12 @@
(ns the-great-game.utils-test
(:require [clojure.test :refer :all]
[the-great-game.utils :refer :all]))
(deftest cyclic-tests
(testing "Detecting cyclic routes"
(let [actual (cyclic? '(:glasgow :edinburgh :glasgow))
expected true]
(is (= actual expected)))
(let [actual (cyclic? '(:edinburgh :dundee :aberdeen :buckie))
expected false]
(is (= actual expected)))))

View file

@ -0,0 +1,33 @@
(ns the-great-game.world.routes-test
(:require [clojure.test :refer :all]
[the-great-game.world.routes :refer :all]
[the-great-game.world.world :refer [default-world]]))
(deftest routing-test
(testing "Routing: possible route"
(let [origin :buckie
destination :glasgow
routes (find-routes (:routes default-world) origin destination)]
(is
(= (first (first routes)) origin)
"Routes should be from the specified origin")
(is
(= (last (first routes)) destination)
"Routes should be from the specified destination")
(is
(= (count (set (map first routes))) 1)
"All routes should have the same origin")
(is
(= (count (set (map last routes))) 1)
"All routes should have the same destination")
(is
(= (count (set (map count routes))) 1)
"All selected routes should have the same length")
))
(testing "Impossible route"
(let [origin :buckie
destination :london ;; not present in the routing map
actual (find-routes (:routes default-world) origin destination)]
(is (nil? actual) "There should be no route returned."))))

View file

@ -0,0 +1,4 @@
(ns the-great-game.world.world-test
(:require [clojure.test :refer :all]
[the-great-game.world.world :refer :all]))