Some work on flow, but mainly tidyup.

This commit is contained in:
Simon Brooke 2023-07-11 08:22:54 +01:00
parent 4f35557b38
commit 866c00bea0
37 changed files with 5840 additions and 623 deletions

View file

@ -1,11 +1,11 @@
(ns mw-engine.core-test
(:require [clojure.test :refer :all]
[mw-engine.core :refer :all]))
(:require [clojure.test :refer [deftest is testing]]
[mw-engine.core :refer [apply-rule]]))
(deftest apply-rule-test
(testing "Application of a single rule"
(let [afn (eval
(fn [cell world]
(fn [cell _world]
(cond
(= (:state cell) :new)
(merge cell {:state :grassland}))))

View file

@ -1,8 +1,8 @@
(ns mw-engine.drainage-test
(:require [clojure.test :refer :all]
[mw-engine.world :as world]
(:require [clojure.test :refer [deftest is testing]]
[mw-engine.drainage :refer [flood-hollow flood-hollows is-hollow]]
[mw-engine.utils :as utils]
[mw-engine.drainage :refer :all]))
[mw-engine.world :as world]))
(deftest is-hollow-test
(testing "detection of hollows"

View file

@ -1,6 +1,7 @@
(ns mw-engine.flow-test
(:require [clojure.test :refer [deftest is testing]]
[mw-engine.flow :refer [coordinate? execute execute-flows flow?
[mw-engine.flow :refer [coordinate? create-flow-percent
create-location execute execute-flows flow?
location?]]
[mw-engine.utils :refer [get-cell merge-cell]]
[mw-engine.world :refer [make-world]]))
@ -52,4 +53,33 @@
dest-q (:q (get-cell transferred 0 1))]
(is (= source-q 2.9))
(is (= inter-q 1.4))
(is (= dest-q 1))))))
(is (= dest-q 1))))
(let [world (make-world 3 3)
world' (merge-cell world {:x 0, :y 0, :state :new :q 5.3})
highdemand {:source {:x 0 :y 0}
:destination {:x 1 :y 1}
:property :q
:quantity 7.4}
transferred (execute world' highdemand)
source-q (:q (get-cell transferred 0 0))
dest-q (:q (get-cell transferred 1 1))
sx 0.0
dx 5.3]
(is (= source-q sx) "The entire stock should have gone;")
(is (= dest-q dx) "Only as much as was available should have arrived."))))
(deftest creator-macro-tests
(testing "Creator macros"
(let [source {:x 1 :y 2 :q 5.7 :state :house}
dest {:x 3 :y 3 :q 1 :state :house}
prop :q]
(let [expected {:x 1, :y 2}
actual (create-location source)]
(is (= actual expected)))
(let [expected {:source {:x 1, :y 2},
:prop :q,
:quantity 1.425,
:destination {:x 3, :y 3}}
actual (create-flow-percent source dest prop 25)]
(is (= actual expected))
(is (= (:quantity actual) (* 0.25 (:q source))))))))

View file

@ -1,9 +1,8 @@
(ns mw-engine.heightmap-test
(:use clojure.java.io)
(:require [clojure.test :refer :all]
[mw-engine.heightmap :refer :all]
[mw-engine.world :as world :only [make-world]]
[clojure.math.combinatorics :as combo]))
(:require [clojure.java.io :refer [as-file]]
[clojure.test :refer [deftest is testing]]
[mw-engine.heightmap :refer [apply-heightmap apply-valuemap]]
[mw-engine.world :refer [make-world]]))
(deftest apply-heightmap-test
(testing "Heightmap functionality"
@ -22,7 +21,7 @@
(is (> (apply + gradients) 0)
"At least some gradients must be positive, none should be negative"))
;; alternate means of making the world, same tests.
(let [world (apply-heightmap (world/make-world 9 9) (as-file "resources/heightmaps/test9x9.png"))
(let [world (apply-heightmap (make-world 9 9) (as-file "resources/heightmaps/test9x9.png"))
altitudes (map #(:altitude %) (flatten world))
gradients (map #(:gradient %) (flatten world))]
(is (= (count world) 9) "World should be 9x9")

View file

@ -1,8 +1,11 @@
(ns mw-engine.utils-test
(:use [mw-engine.world :as world])
(:require [clojure.test :refer :all]
[clojure.math.combinatorics :as combo]
[mw-engine.utils :refer :all]))
(:require [clojure.math.combinatorics :as combo]
[clojure.test :refer [deftest is testing]]
[mw-engine.utils :refer [get-cell get-least-cell get-most-cell
get-neighbours
get-neighbours-with-property-value
map-world merge-cell set-property]]
[mw-engine.world :refer [make-world]]))
(deftest abs-test
(testing "Absolute value function"
@ -116,8 +119,8 @@
(let [w1a (make-world 3 3)
w2b (set-property w1a (get-cell w1a 1 1) :location :centre)
w3c (set-property w2b 0 0 :location :top-left)]
(is (= (:location (get-cell w3c 0 0) :top-left)))
(is (= (:location (get-cell w3c 1 1) :centre)))
(is (= (:location (get-cell w3c 0 0)) :top-left))
(is (= (:location (get-cell w3c 1 1)) :centre))
(is (nil? (:location (get-cell w3c 2 2)))
"Cell at 2,2 should not have location set")
(is (= (count (remove nil? (map #(:location %) (flatten w3c)))) 2)

View file

@ -1,6 +1,6 @@
(ns mw-engine.world-test
(:require [clojure.test :refer :all]
[mw-engine.world :refer :all]
(:require [clojure.test :refer [deftest is testing]]
[mw-engine.world :refer [make-world]]
[clojure.math.combinatorics :as combo]))
(deftest genesis-test