mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-06-09 08:29:32 +00:00
whitespace and other cosmetic changes
This commit is contained in:
parent
47f922512f
commit
5893e4b5e6
|
@ -15,15 +15,13 @@
|
||||||
:*GAME-SECONDS-PER-TICK* *GAME-SECONDS-PER-TICK*})
|
:*GAME-SECONDS-PER-TICK* *GAME-SECONDS-PER-TICK*})
|
||||||
|
|
||||||
(defn parse-program-names
|
(defn parse-program-names
|
||||||
"takes a string parameter from the browser and returns a seqence
|
"takes a string parameter from the browser and returns a sequence
|
||||||
of program keys"
|
of program keys"
|
||||||
[programs-str]
|
[programs-str]
|
||||||
(map keyword (split programs-str #"[,\s]\s*")))
|
(map keyword (split programs-str #"[,\s]\s*")))
|
||||||
|
|
||||||
(defn get-programs
|
(defn get-programs
|
||||||
"gets a sequence of programs from the source-code
|
"gets a sequence of five programs from the source-code repository."
|
||||||
repository. some may be repeats. discards failed matches.
|
|
||||||
cuts off after five."
|
|
||||||
[program-keys]
|
[program-keys]
|
||||||
(take 5 (filter identity (map #(% source-programs/programs) program-keys))))
|
(take 5 (filter identity (map #(% source-programs/programs) program-keys))))
|
||||||
|
|
||||||
|
@ -37,15 +35,15 @@
|
||||||
programs (get-programs program-names)
|
programs (get-programs program-names)
|
||||||
world (world/init-world programs)
|
world (world/init-world programs)
|
||||||
combined-worlds (world/build-combined-worlds world)
|
combined-worlds (world/build-combined-worlds world)
|
||||||
worlds-for-browser (browser/worlds-for-browser combined-worlds)]
|
worlds-for-browser (browser/worlds-for-browser combined-worlds)]
|
||||||
{:games (merge games {next-id worlds-for-browser})
|
{:games (merge games {next-id worlds-for-browser})
|
||||||
:next-id (inc next-id)}))
|
:next-id (inc next-id)}))
|
||||||
|
|
||||||
(defn take-drop-send
|
(defn take-drop-send
|
||||||
"takes the games-store atom, a game id, and a number n,
|
"takes the games-store atom, a game id, and a number n,
|
||||||
and returns a collection of the first n items from that game,
|
and returns a collection of the first n items from that game,
|
||||||
then drops those items from the game in the atom's state."
|
then drops those items from the game in the atom's state."
|
||||||
[games-store id n]
|
[games-store id n]
|
||||||
(let [coll (get-in @games-store [:games id])]
|
(let [coll (get-in @games-store [:games id])]
|
||||||
(swap! games-store #(assoc-in % [:games id] (drop n coll)))
|
(swap! games-store #(assoc-in % [:games id] (drop n coll)))
|
||||||
(take n coll)))
|
(take n coll)))
|
||||||
|
@ -81,4 +79,4 @@
|
||||||
(wrap-file "public")
|
(wrap-file "public")
|
||||||
(wrap-json-response)
|
(wrap-json-response)
|
||||||
(wrap-json-body)
|
(wrap-json-body)
|
||||||
(wrap-params)))
|
(wrap-params)))
|
||||||
|
|
|
@ -2,18 +2,18 @@
|
||||||
(:require [clojure.test :refer :all]
|
(:require [clojure.test :refer :all]
|
||||||
[robotwar.handler :refer :all]
|
[robotwar.handler :refer :all]
|
||||||
[ring.mock.request :as mock]))
|
[ring.mock.request :as mock]))
|
||||||
|
|
||||||
|
|
||||||
(deftest app-handler-test
|
(deftest app-handler-test
|
||||||
(testing "program-names"
|
(testing "program-names"
|
||||||
(let [response (app (mock/request :get "/program-names"))]
|
(let [response (app (mock/request :get "/program-names"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
(is (.contains (:body response) "mover"))))
|
(is (.contains (:body response) "mover"))))
|
||||||
|
|
||||||
(testing "not-found route"
|
(testing "not-found route"
|
||||||
(let [response (app (mock/request :get "/invalid"))]
|
(let [response (app (mock/request :get "/invalid"))]
|
||||||
(is (= (:status response) 404))))
|
(is (= (:status response) 404))))
|
||||||
|
|
||||||
(testing "files"
|
(testing "files"
|
||||||
(let [response (app (mock/request :get "/index.html"))]
|
(let [response (app (mock/request :get "/index.html"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
|
@ -21,13 +21,13 @@
|
||||||
(let [response (app (mock/request :get "/js/main.js"))]
|
(let [response (app (mock/request :get "/js/main.js"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
(is (.contains (slurp (:body response)) "function"))))
|
(is (.contains (slurp (:body response)) "function"))))
|
||||||
|
|
||||||
(testing "worlds route"
|
(testing "worlds route"
|
||||||
(let [response (app (mock/request :get "/worlds/0/99"))]
|
(let [response (app (mock/request :get "/worlds/0/99"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
(is (.contains (:body response) "["))))
|
(is (.contains (:body response) "["))))
|
||||||
|
|
||||||
(testing "init route"
|
(testing "init route"
|
||||||
(let [response (app (mock/request :get "/init?programs=mover"))]
|
(let [response (app (mock/request :get "/init?programs=mover"))]
|
||||||
(is (= (:status response) 200))
|
(is (= (:status response) 200))
|
||||||
(is (.contains (:body response) "game-info")))))
|
(is (.contains (:body response) "game-info")))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user