2013-08-12 04:14:44 +00:00
|
|
|
(ns robotwar.robot-test
|
|
|
|
(:use [clojure.test]
|
|
|
|
[midje.sweet]
|
2013-08-15 15:31:37 +00:00
|
|
|
[robotwar.robot]
|
|
|
|
[robotwar.constants])
|
2013-08-12 04:14:44 +00:00
|
|
|
(:require [robotwar.register :as register]
|
|
|
|
[robotwar.world :as world]))
|
2013-08-11 16:15:50 +00:00
|
|
|
|
2013-08-12 04:14:44 +00:00
|
|
|
(def world (world/init-world 256.0 256.0 [""]))
|
|
|
|
|
2013-08-12 13:50:22 +00:00
|
|
|
; The next four tests are pretty much cut and pasted from each other. So sue me.
|
|
|
|
; To change them significantly, delete three of them and build up from the first one
|
|
|
|
; again. TODO: write a wrapper for these.
|
|
|
|
|
2013-08-12 13:47:49 +00:00
|
|
|
(deftest positive-acceleration-x-test
|
2013-08-12 04:14:44 +00:00
|
|
|
(testing "application of SPEEDX register in
|
|
|
|
positive direction has expected behavior"
|
2013-08-12 13:42:24 +00:00
|
|
|
(let [zeroed-world (assoc-in world [:robots 0 :pos-x] 0.0)
|
2013-08-12 04:14:44 +00:00
|
|
|
zeroed-registers (get-in world [:robots 0 :brain :registers])
|
|
|
|
speedy-world (register/write-register (zeroed-registers "SPEEDX") zeroed-world 140)
|
2013-08-15 03:13:49 +00:00
|
|
|
speedy-worlds (iterate (fn [{[robot] :robots :as world}]
|
|
|
|
(binding [*GAME-SECONDS-PER-TICK* 1.0]
|
|
|
|
(step-robot robot world)))
|
|
|
|
speedy-world)]
|
2013-08-12 04:14:44 +00:00
|
|
|
(is (= (take 6 (map (fn [world]
|
|
|
|
{:pos-x (get-in world [:robots 0 :pos-x])
|
|
|
|
:v-x (get-in world [:robots 0 :v-x])
|
|
|
|
:desired-v-x (get-in world [:robots 0 :desired-v-x])})
|
|
|
|
speedy-worlds))
|
|
|
|
[{:pos-x 0.0, :v-x 0.0, :desired-v-x 14.0}
|
|
|
|
{:pos-x 2.0, :v-x 4.0, :desired-v-x 14.0}
|
|
|
|
{:pos-x 8.0, :v-x 8.0, :desired-v-x 14.0}
|
|
|
|
{:pos-x 18.0, :v-x 12.0, :desired-v-x 14.0}
|
|
|
|
{:pos-x 31.5, :v-x 14.0, :desired-v-x 14.0}
|
|
|
|
{:pos-x 45.5, :v-x 14.0, :desired-v-x 14.0}])))))
|
2013-08-11 16:15:50 +00:00
|
|
|
|
2013-08-12 13:47:49 +00:00
|
|
|
(deftest negative-acceleration-x-test
|
|
|
|
(testing "application of SPEEDX register in
|
|
|
|
negative direction has expected behavior"
|
|
|
|
(let [zeroed-world (assoc-in world [:robots 0 :pos-x] 100.0)
|
|
|
|
zeroed-registers (get-in world [:robots 0 :brain :registers])
|
|
|
|
speedy-world (register/write-register (zeroed-registers "SPEEDX") zeroed-world -140)
|
2013-08-15 03:13:49 +00:00
|
|
|
speedy-worlds (iterate (fn [{[robot] :robots :as world}]
|
|
|
|
(binding [*GAME-SECONDS-PER-TICK* 1.0]
|
|
|
|
(step-robot robot world)))
|
|
|
|
speedy-world)]
|
2013-08-12 13:47:49 +00:00
|
|
|
(is (= (take 6 (map (fn [world]
|
|
|
|
{:pos-x (get-in world [:robots 0 :pos-x])
|
|
|
|
:v-x (get-in world [:robots 0 :v-x])
|
|
|
|
:desired-v-x (get-in world [:robots 0 :desired-v-x])})
|
|
|
|
speedy-worlds))
|
|
|
|
[{:pos-x 100.0, :v-x 0.0, :desired-v-x -14.0}
|
|
|
|
{:pos-x 98.0, :v-x -4.0, :desired-v-x -14.0}
|
|
|
|
{:pos-x 92.0, :v-x -8.0, :desired-v-x -14.0}
|
|
|
|
{:pos-x 82.0, :v-x -12.0, :desired-v-x -14.0}
|
|
|
|
{:pos-x 68.5, :v-x -14.0, :desired-v-x -14.0}
|
|
|
|
{:pos-x 54.5, :v-x -14.0, :desired-v-x -14.0}])))))
|
|
|
|
|
2013-08-12 13:53:02 +00:00
|
|
|
(deftest positive-acceleration-y-test
|
|
|
|
(testing "application of SPEEDY register in
|
|
|
|
positive direction has expected behavior"
|
|
|
|
(let [zeroed-world (assoc-in world [:robots 0 :pos-y] 0.0)
|
|
|
|
zeroed-registers (get-in world [:robots 0 :brain :registers])
|
|
|
|
speedy-world (register/write-register (zeroed-registers "SPEEDY") zeroed-world 140)
|
2013-08-15 03:13:49 +00:00
|
|
|
speedy-worlds (iterate (fn [{[robot] :robots :as world}]
|
|
|
|
(binding [*GAME-SECONDS-PER-TICK* 1.0]
|
|
|
|
(step-robot robot world)))
|
|
|
|
speedy-world)]
|
2013-08-12 13:53:02 +00:00
|
|
|
(is (= (take 6 (map (fn [world]
|
|
|
|
{:pos-y (get-in world [:robots 0 :pos-y])
|
|
|
|
:v-y (get-in world [:robots 0 :v-y])
|
|
|
|
:desired-v-y (get-in world [:robots 0 :desired-v-y])})
|
|
|
|
speedy-worlds))
|
|
|
|
[{:pos-y 0.0, :v-y 0.0, :desired-v-y 14.0}
|
|
|
|
{:pos-y 2.0, :v-y 4.0, :desired-v-y 14.0}
|
|
|
|
{:pos-y 8.0, :v-y 8.0, :desired-v-y 14.0}
|
|
|
|
{:pos-y 18.0, :v-y 12.0, :desired-v-y 14.0}
|
|
|
|
{:pos-y 31.5, :v-y 14.0, :desired-v-y 14.0}
|
|
|
|
{:pos-y 45.5, :v-y 14.0, :desired-v-y 14.0}])))))
|
|
|
|
|
|
|
|
(deftest negative-acceleration-y-test
|
|
|
|
(testing "application of SPEEDY register in
|
|
|
|
negative direction has expected behavior"
|
|
|
|
(let [zeroed-world (assoc-in world [:robots 0 :pos-y] 100.0)
|
|
|
|
zeroed-registers (get-in world [:robots 0 :brain :registers])
|
|
|
|
speedy-world (register/write-register (zeroed-registers "SPEEDY") zeroed-world -140)
|
2013-08-15 03:13:49 +00:00
|
|
|
speedy-worlds (iterate (fn [{[robot] :robots :as world}]
|
|
|
|
(binding [*GAME-SECONDS-PER-TICK* 1.0]
|
|
|
|
(step-robot robot world)))
|
|
|
|
speedy-world)]
|
2013-08-12 13:53:02 +00:00
|
|
|
(is (= (take 6 (map (fn [world]
|
|
|
|
{:pos-y (get-in world [:robots 0 :pos-y])
|
|
|
|
:v-y (get-in world [:robots 0 :v-y])
|
|
|
|
:desired-v-y (get-in world [:robots 0 :desired-v-y])})
|
|
|
|
speedy-worlds))
|
|
|
|
[{:pos-y 100.0, :v-y 0.0, :desired-v-y -14.0}
|
|
|
|
{:pos-y 98.0, :v-y -4.0, :desired-v-y -14.0}
|
|
|
|
{:pos-y 92.0, :v-y -8.0, :desired-v-y -14.0}
|
|
|
|
{:pos-y 82.0, :v-y -12.0, :desired-v-y -14.0}
|
|
|
|
{:pos-y 68.5, :v-y -14.0, :desired-v-y -14.0}
|
|
|
|
{:pos-y 54.5, :v-y -14.0, :desired-v-y -14.0}])))))
|
|
|
|
|