From 63ab384440a6e6813196b914813914bc43674fa8 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Fri, 12 Jun 2015 16:30:29 +0200 Subject: Added new tests --- test/game_state.cpp | 39 +++++++++++++++++++++++++++++++++++---- test/move_string_mapper.cpp | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 test/move_string_mapper.cpp (limited to 'test') diff --git a/test/game_state.cpp b/test/game_state.cpp index 0887b05..467a665 100644 --- a/test/game_state.cpp +++ b/test/game_state.cpp @@ -19,7 +19,7 @@ SCENARIO("game state is read from istream") file << "# VVV #" << std::endl; file << "# --- --- #" << std::endl; file << "# --- --- #" << std::endl; - file << "# --- --- #" << std::endl; + file << "# --- i --- #" << std::endl; file << "# #" << std::endl; file << "# #" << std::endl; file << "# #" << std::endl; @@ -29,10 +29,10 @@ SCENARIO("game state is read from istream") file << "# #" << std::endl; file << "# x x x #" << std::endl; file << "# #" << std::endl; + file << "# | #" << std::endl; file << "# #" << std::endl; file << "# #" << std::endl; - file << "# #" << std::endl; - file << "# #" << std::endl; + file << "# ! #" << std::endl; file << "# --- --- #" << std::endl; file << "# --- --- #" << std::endl; file << "# --- --- #" << std::endl; @@ -49,10 +49,41 @@ SCENARIO("game state is read from istream") WHEN ("the game state is initilized") { GameState state(std::move(file)); - THEN("the map is read correctly") + + THEN("the aliens are read correctly") { auto aliens = state.aliens(); REQUIRE(aliens.size() == 6); + REQUIRE(aliens[0].x() == 10); + REQUIRE(aliens[0].y() == 11); + REQUIRE(aliens[5].x() == 16); + REQUIRE(aliens[5].y() == 13); + } + + THEN("the shields are read correctly") + { + auto shields = state.shields(); + REQUIRE(shields.size() == 36); + } + + THEN("the enemy bullets are read correctly") + { + auto bullets = state.bullets(); + REQUIRE(bullets.size() == 2); + } + + THEN("the player missiles are read correctly") + { + auto missiles = state.missiles(); + REQUIRE(missiles.size() == 1); + REQUIRE(missiles[0].x() == 11); + REQUIRE(missiles[0].y() == 18); + } + + THEN("the spaceships are read correctly") + { + auto spaceships = state.spaceships(); + REQUIRE(spaceships.size() == 2); } } } diff --git a/test/move_string_mapper.cpp b/test/move_string_mapper.cpp new file mode 100644 index 0000000..ab167e3 --- /dev/null +++ b/test/move_string_mapper.cpp @@ -0,0 +1,23 @@ +#include "catch.hpp" +#include "move.h" +#include +#include "move_string_mapper.h" + +SCENARIO("Writing a move") +{ + GIVEN("A Move") + { + Move move = Move::MOVE_LEFT; + + WHEN("It is mapped to a string") + { + std::string moveString = MoveStringMapper().toString(move); + + THEN("The string is correct") + { + REQUIRE(moveString == "MoveLeft"); + } + } + + } +} -- cgit v1.2.3