Considerable refactoring based on the new map-world utility function.

This commit is contained in:
Simon Brooke 2014-07-25 11:49:50 +01:00
parent 4949e30f69
commit 75475ece29
5 changed files with 51 additions and 51 deletions

View file

@ -10,15 +10,15 @@
(= (:state cell) :new)
(merge cell {:state :grassland}))))
pair (list afn "Test source")]
(is (nil? (apply-rule {:state :water} nil afn))
(is (nil? (apply-rule nil {:state :water} afn))
"Rule shouldn't fire when state is wrong")
(is (nil? (apply-rule {:state :water} nil pair))
(is (nil? (apply-rule nil {:state :water} pair))
"Rule shouldn't fire when state is wrong")
(is (= (:state (apply-rule {:state :new} nil afn)) :grassland)
(is (= (:state (apply-rule nil {:state :new} afn)) :grassland)
"Rule should fire when state is correct")
(is (= (:state (apply-rule {:state :new} nil pair)) :grassland)
(is (= (:state (apply-rule nil {:state :new} pair)) :grassland)
"Rule should fire when state is correct")
(is (nil? (:rule (apply-rule {:state :new} nil afn)))
(is (nil? (:rule (apply-rule nil {:state :new} afn)))
"No rule text if not provided")
(is (= (:rule (apply-rule {:state :new} nil pair)) "Test source")
(is (= (:rule (apply-rule nil {:state :new} pair)) "Test source")
"Rule text cached on cell if provided"))))

View file

@ -143,4 +143,19 @@
(range 0 3)))))
"General sanity test")
)))
(deftest map-world-test
(testing "map-world utility function"
(let [w1a (make-world 3 3)
w2b (map-world w1a #(merge %2 {:test true}))
w3c (map-world w2b #(merge %2 {:number (+ %3 %4)}) '(4 4))]
(is (= (count w1a) (count w3c)) "No change in world size")
(is (= (count (flatten w1a)) (count (flatten w3c)))
"No change in world size")
(is (empty? (remove true? (map #(:test %) (flatten w3c))))
"All cells should have property 'test' set to true")
(is (empty? (remove #(= % 8) (map #(:number %) (flatten w3c))))
"All cells should have property 'number' set to 8"))))