|
| 1 | +;; -*- coding: utf-8 -*- |
| 2 | +;; |
| 3 | +;; Copyright (c) 2010-2015 Tuukka Turto |
| 4 | +;; |
| 5 | +;; Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +;; of this software and associated documentation files (the "Software"), to deal |
| 7 | +;; in the Software without restriction, including without limitation the rights |
| 8 | +;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +;; copies of the Software, and to permit persons to whom the Software is |
| 10 | +;; furnished to do so, subject to the following conditions: |
| 11 | +;; |
| 12 | +;; The above copyright notice and this permission notice shall be included in |
| 13 | +;; all copies or substantial portions of the Software. |
| 14 | +;; |
| 15 | +;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +;; THE SOFTWARE. |
| 22 | + |
| 23 | +(require pyherc.macros) |
| 24 | + |
| 25 | +(import [hamcrest [assert-that has-item]] |
| 26 | +[pyherc.data.traps [RemoteTrigger CharacterSpawner]] |
| 27 | + [pyherc.data.constants [Direction]] |
| 28 | + [pyherc.data [add-character add-trap get-characters]] |
| 29 | + [pyherc.ports [set-action-factory move]] |
| 30 | + [pyherc.test.builders [LevelBuilder CharacterBuilder |
| 31 | + ActionFactoryBuilder]]) |
| 32 | + |
| 33 | +(defn setup [] |
| 34 | + "setup test case" |
| 35 | + (let [[level (-> (LevelBuilder) |
| 36 | + (.build))] |
| 37 | + [character₀ (-> (CharacterBuilder) |
| 38 | + (.build))] |
| 39 | + [character₁ (-> (CharacterBuilder) |
| 40 | + (.build))] |
| 41 | + [spawner (CharacterSpawner (fn [] [character₁]))] |
| 42 | + [trigger (RemoteTrigger spawner)]] |
| 43 | + (set-action-factory (-> (ActionFactoryBuilder) |
| 44 | + (.with-move-factory) |
| 45 | + (.build))) |
| 46 | + {:level level |
| 47 | + :spawner spawner |
| 48 | + :trigger trigger |
| 49 | + :character₀ character₀ |
| 50 | + :character₁ character₁})) |
| 51 | + |
| 52 | +(defn test-spawning-character [] |
| 53 | + "character spawner can create new character on level" |
| 54 | + (let [[context (setup)] |
| 55 | + [level (:level context)] |
| 56 | + [character₀ (:character₀ context)] |
| 57 | + [character₁ (:character₁ context)] |
| 58 | + [spawner (:spawner context)] |
| 59 | + [trigger (:trigger context)]] |
| 60 | + (add-character level #t(1 1) character₀) |
| 61 | + (add-trap level #t(2 1) trigger) |
| 62 | + (add-trap level #t(5 5) spawner) |
| 63 | + (move character₀ Direction.east) |
| 64 | + (assert-that (list (get-characters level)) |
| 65 | + (has-item character₁)))) |
0 commit comments