Skip to content

Commit

Permalink
Add tests for update function
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hendrix and Yulia Tolskaya committed Jun 18, 2015
1 parent fcc6fc6 commit 938f104
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions test/RogueTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,44 @@ import String
tests : Test
tests = suite "A Test Suite"
[ test_updateGameMap_does_not_move_outside_of_bounds

, test_update_moves_currentPlayerLocation
]

test_update_moves_currentPlayerLocation : Test
test_update_moves_currentPlayerLocation =
let
defaultGameMap = gameMap 2
game_map = { defaultGameMap | currentPlayerLocation <- (0,0) }
player = Player
game = Game game_map player
down_right = Input {x=1,y=-1}
in
test "Update moves currentPlayerLocation" (
assertEqual (update down_right game).gameMap.currentPlayerLocation (1,1)
)

test_updateGameMap_does_not_move_outside_of_bounds : Test
test_updateGameMap_does_not_move_outside_of_bounds =
let
game = gameMap 2
gameAtTopLeft = { game | currentPlayerLocation <- (0,0) }
game_map = gameMap 2
gameMapAtTopLeft = { game_map | currentPlayerLocation <- (0,0) }
left = Input { x =-1, y = 0 }
up = Input { x=0, y=1 }
gameAtBottomRight = { game | currentPlayerLocation <- (1,1) }
gameMapAtBottomRight = { game_map | currentPlayerLocation <- (1,1) }
right = Input { x =1, y = 0 }
down = Input { x=0, y=-1 }
in
suite "Update does not move outside of bounds"
[ test "Left" (
assertEqual gameAtTopLeft.currentPlayerLocation (updateGameMap left gameAtTopLeft).currentPlayerLocation
assertEqual gameMapAtTopLeft.currentPlayerLocation (updateGameMap left gameMapAtTopLeft).currentPlayerLocation
)
, test "Up" (
assertEqual gameAtTopLeft.currentPlayerLocation (updateGameMap up gameAtTopLeft).currentPlayerLocation
assertEqual gameMapAtTopLeft.currentPlayerLocation (updateGameMap up gameMapAtTopLeft).currentPlayerLocation
)
, test "Right" (
assertEqual gameAtBottomRight.currentPlayerLocation (updateGameMap right gameAtBottomRight).currentPlayerLocation
assertEqual gameMapAtBottomRight.currentPlayerLocation (updateGameMap right gameMapAtBottomRight).currentPlayerLocation
)
, test "Down" (
assertEqual gameAtBottomRight.currentPlayerLocation (updateGameMap down gameAtBottomRight).currentPlayerLocation
assertEqual gameMapAtBottomRight.currentPlayerLocation (updateGameMap down gameMapAtBottomRight).currentPlayerLocation
)
]

0 comments on commit 938f104

Please sign in to comment.