Browse Source

Write failing test for tower-level

Ryan Rix 3 years ago
parent
commit
b313f727a0
1 changed files with 26 additions and 0 deletions
  1. 26 0
      test/rl/tower_level_test.clj

+ 26 - 0
test/rl/tower_level_test.clj

@@ -0,0 +1,26 @@
+(ns rl.tower-level-test
+  (:require [rl.tower-level :as tl]
+            [clojure.test :refer :all]))
+
+(defn add-room [level]
+  (tl/with-room
+    level
+    (+ 3 (rand-int 2))
+    (+ 3 (rand-int 2))))
+
+(deftest with-room
+  (testing "doesn't inject nils after one room"
+    (let [nv (-> (tl/level-struct 10 10)
+                 add-room)
+          nv (:data nv)]
+      (doseq [x (range 10)
+              y (range 10)]
+        (is (not (nil? (get (get nv y) x)))))))
+  (testing "doesn't inject nils after two rooms"
+    (let [nv (-> (tl/level-struct 10 10)
+                 add-room
+                 add-room)
+          nv (:data nv)]
+      (doseq [x (range 10)
+              y (range 10)]
+        (is (not (nil? (get (get nv y) x))))))))