|
@@ -0,0 +1,98 @@
|
|
|
|
+(ns bombnet.game-test
|
|
|
|
+ (:require [clojure.test :refer :all]
|
|
|
|
+ [bombnet.game :refer :all]))
|
|
|
|
+
|
|
|
|
+(deftest board-test
|
|
|
|
+ (testing "Board size is correct"
|
|
|
|
+ (let [board (new-board 5 7)]
|
|
|
|
+ (is (= (count board) 7) "Check height")
|
|
|
|
+ (is (= (count (get board 0)) 5) "Check width")))
|
|
|
|
+ (testing "Can get cells"
|
|
|
|
+ (let [board [["0" "1" "2"] ["3" "4" "5"]]]
|
|
|
|
+ (is (= (get-cell board [0 0]) "0"))
|
|
|
|
+ (is (= (get-cell board [1 0]) "1"))
|
|
|
|
+ (is (= (get-cell board [1 1]) "4"))
|
|
|
|
+ (is (= (get-cell board [2 1]) "5")))))
|
|
|
|
+
|
|
|
|
+(deftest player-test
|
|
|
|
+ (testing "Player can move"
|
|
|
|
+ (let [p (new-player "p1")
|
|
|
|
+ check (fn [p pos]
|
|
|
|
+ (is (= (:pos p) pos)))]
|
|
|
|
+ (check (move-player p 3 3) [3 3])
|
|
|
|
+ (check (move-player p 2 4) [2 4])
|
|
|
|
+ (check (move-player p "up") [1 0])
|
|
|
|
+ (check (move-player p "down") [1 2])
|
|
|
|
+ (check (move-player p "left") [0 1])
|
|
|
|
+ (check (move-player p "right") [2 1]))))
|
|
|
|
+
|
|
|
|
+(deftest check-test
|
|
|
|
+ (testing "Check valid positions"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1]}
|
|
|
|
+ {:id 2 :pos [2 2]}
|
|
|
|
+ {:id 3 :pos [1 2]}
|
|
|
|
+ {:id 4 :pos [1 2]}
|
|
|
|
+ {:id 5 :pos [1 3]}]
|
|
|
|
+ :bombs [{:pos [1 3]}]}]
|
|
|
|
+ (is (= #{1} (check-positions state))))))
|
|
|
|
+
|
|
|
|
+(deftest move-test
|
|
|
|
+ (testing "Can walk normally #> #"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [2 1] (get-in new-state [:players 0 :pos])))))
|
|
|
|
+ (testing "Cannot walk through walls #< #"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "left"}}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [1 1] (get-in new-state [:players 0 :pos])))))
|
|
|
|
+ (testing "Cannot walk through bombs #>Q #"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}]
|
|
|
|
+ :bombs [{:pos [2 1]}]}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [1 1] (get-in new-state [:players 0 :pos])))))
|
|
|
|
+ (testing "Cannot walk through people #>@ "
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}
|
|
|
|
+ {:id 2 :pos [2 1]}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [1 1] (get-in new-state [:players 0 :pos])))))
|
|
|
|
+ (testing "Allow simultaneous movement #>> #"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}
|
|
|
|
+ {:id 2 :pos [2 1] :action {:type "move" :dir "right"}}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [2 1] (get-in new-state [:players 0 :pos])))
|
|
|
|
+ (is (= [3 1] (get-in new-state [:players 1 :pos])))))
|
|
|
|
+ (testing "Cannot swap people #>< #"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}
|
|
|
|
+ {:id 2 :pos [2 1] :action {:type "move" :dir "left"}}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [1 1] (get-in new-state [:players 0 :pos])))
|
|
|
|
+ (is (= [2 1] (get-in new-state [:players 1 :pos])))))
|
|
|
|
+ (testing "Cannot contest the same square #> <#"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}
|
|
|
|
+ {:id 2 :pos [3 1] :action {:type "move" :dir "left"}}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [1 1] (get-in new-state [:players 0 :pos])))
|
|
|
|
+ (is (= [3 1] (get-in new-state [:players 1 :pos])))))
|
|
|
|
+ (testing "Resolves recursively #>>@#"
|
|
|
|
+ (let [state {:board (new-board 5 5)
|
|
|
|
+ :players [{:id 1 :pos [1 1] :action {:type "move" :dir "right"}}
|
|
|
|
+ {:id 2 :pos [2 1] :action {:type "move" :dir "right"}}
|
|
|
|
+ {:id 3 :pos [3 1]}]
|
|
|
|
+ :bombs []}
|
|
|
|
+ new-state (perform-movement state)]
|
|
|
|
+ (is (= [1 1] (get-in new-state [:players 0 :pos])))
|
|
|
|
+ (is (= [2 1] (get-in new-state [:players 1 :pos]))))))
|