Work in support of new development in the-great-game, q.v.

This commit is contained in:
Simon Brooke 2024-04-05 22:13:13 +01:00
parent 3e1e3052d1
commit 93dab8067b
7 changed files with 139 additions and 13 deletions

View file

@ -1,12 +1,13 @@
(ns mw-engine.core-test
(:require [clojure.test :refer [deftest is testing]]
[mw-engine.core :refer [apply-rule transform-world]]
[mw-engine.core :refer [*with-history* apply-rule transform-world]]
[mw-engine.utils :refer [map-world]]
[mw-engine.world :refer [make-world]]))
(deftest apply-rule-test
(testing "Application of a single rule"
(let [afn (vary-meta
(binding [*with-history* true]
(let [afn (vary-meta
(eval
(fn [cell _world]
(cond
@ -19,7 +20,21 @@
(is (= (:state (apply-rule nil {:state :new} afn)) :grassland)
"Rule should fire when state is correct")
(is (seq? (:history (apply-rule nil {:state :new} afn)))
"Event cached on history of cell"))))
"Event cached on history of cell")))
(binding [*with-history* false]
(let [afn (vary-meta
(eval
(fn [cell _world]
(cond
(= (:state cell) :new)
(merge cell {:state :grassland}))))
merge {:rule-type :production
:rule "Test source"})
modified-cell (apply-rule nil {:state :new} afn)]
(is (= (:state modified-cell) :grassland)
"Rule should fire when state is correct")
(is (nil? (:history modified-cell))
"No event cached on history of cell")))))
(deftest transform-world-tests
(testing "Application of a single rule"