Commits

trikitrok committed 58e60d8 Draft

Renamed test suite for Game class

  • Participants
  • Parent commits d5d5067

Comments (0)

Files changed (2)

File src/test/GameTests.cpp

+#include <CppUTest/TestHarness.h>
+
+#include "../Game.h"
+
+namespace Players
+{
+	const std::string PLAYER_ONE = "koko";
+	const std::string PLAYER_TWO = "triki";
+}
+
+TEST_GROUP(GameTests)
+{
+	Game * game;
+
+	void setup() {
+		game = new Game(Players::PLAYER_ONE, Players::PLAYER_TWO);
+	}
+
+	void teardown() {
+		delete game;
+	}
+
+	void makePlayerWinSeveralPoints(const std::string & player, unsigned int numPoints)
+	{
+		for(unsigned int i=0; i < numPoints; ++i)
+		{
+			game->pointTo(player);
+		}
+	}
+
+	void gameGetToDeuce()
+	{
+		makePlayerWinSeveralPoints(Players::PLAYER_ONE, 3);
+		makePlayerWinSeveralPoints(Players::PLAYER_TWO, 3);
+
+	}
+
+	void makePlayerWin(const std::string & player)
+	{
+		makePlayerWinSeveralPoints(player, 4);
+	}
+};
+
+TEST(GameTests, initialScoreIsZero)
+{
+	CHECK("Love-Love" == game->score());
+}
+
+TEST(GameTests, playersCanWinSeveralPoints)
+{
+	game->pointTo(Players::PLAYER_ONE);
+	CHECK("Fifteen-Love" == game->score());
+
+	game->pointTo(Players::PLAYER_ONE);
+	CHECK("Thirty-Love" == game->score());
+
+	game->pointTo(Players::PLAYER_ONE);
+	CHECK("Forty-Love" == game->score());
+
+	game->pointTo(Players::PLAYER_TWO);
+	CHECK("Forty-Fifteen" == game->score());
+
+	game->pointTo(Players::PLAYER_TWO);
+	CHECK("Forty-Thirty" == game->score());
+}
+
+TEST(GameTests, gameIsOverAfterPlayerOneWinsFirstForPoints)
+{
+	makePlayerWin(Players::PLAYER_ONE);
+	CHECK(game->isOver());
+}
+
+TEST(GameTests, gameIsOverAfterPlayerTwoWinsFirstForPoints)
+{
+	makePlayerWin(Players::PLAYER_TWO);
+	CHECK(game->isOver());
+}
+
+TEST(GameTests, scoreDoesNotChangeAfterAPlayerWins)
+{
+	makePlayerWin(Players::PLAYER_ONE);
+
+	std::string PLAYER_ONE_WON = Players::PLAYER_ONE + " won!";
+
+	game->pointTo(Players::PLAYER_ONE);
+	CHECK(PLAYER_ONE_WON == game->score());
+
+	game->pointTo(Players::PLAYER_TWO);
+	CHECK(PLAYER_ONE_WON == game->score());
+}
+
+TEST(GameTests, gameIsNotOverIfNoOneGetsFirstToForty)
+{
+	CHECK(not game->isOver());
+	makePlayerWinSeveralPoints(Players::PLAYER_ONE, 3);
+	CHECK(not game->isOver());
+}
+
+TEST(GameTests, thereIsDeuce)
+{
+	gameGetToDeuce();
+	CHECK("Deuce" == game->score());
+}
+
+TEST(GameTests, gameIsNotOverWhenThereIsDeuce)
+{
+	gameGetToDeuce();
+	CHECK(not game->isOver());
+}
+
+TEST(GameTests, thereIsAdvantage)
+{
+	gameGetToDeuce();
+	game->pointTo(Players::PLAYER_ONE);
+
+	CHECK("Advantage for koko" == game->score());
+}
+
+TEST(GameTests, backToDeuce)
+{
+	gameGetToDeuce();
+	game->pointTo(Players::PLAYER_ONE);
+	game->pointTo(Players::PLAYER_TWO);
+	CHECK("Deuce" == game->score());
+}
+
+TEST(GameTests, thePlayerWithAdvantageWins)
+{
+	gameGetToDeuce();
+	game->pointTo(Players::PLAYER_ONE); // Advantage for player one
+	game->pointTo(Players::PLAYER_TWO); // Deuce again
+	game->pointTo(Players::PLAYER_TWO); // Advantage for player two
+	game->pointTo(Players::PLAYER_TWO);
+
+	std::string PLAYER_TWO_WON = Players::PLAYER_TWO + " won!";
+
+	CHECK(PLAYER_TWO_WON == game->score());
+}

File src/test/TennisTests.cpp

-#include <CppUTest/TestHarness.h>
-
-#include "../Game.h"
-
-namespace Players
-{
-	const std::string PLAYER_ONE = "koko";
-	const std::string PLAYER_TWO = "triki";
-}
-
-TEST_GROUP(TennisTests)
-{
-	Game * game;
-
-	void setup() {
-		game = new Game(Players::PLAYER_ONE, Players::PLAYER_TWO);
-	}
-
-	void teardown() {
-		delete game;
-	}
-
-	void makePlayerWinSeveralPoints(const std::string & player, unsigned int numPoints)
-	{
-		for(unsigned int i=0; i < numPoints; ++i)
-		{
-			game->pointTo(player);
-		}
-	}
-
-	void gameGetToDeuce()
-	{
-		makePlayerWinSeveralPoints(Players::PLAYER_ONE, 3);
-		makePlayerWinSeveralPoints(Players::PLAYER_TWO, 3);
-
-	}
-
-	void makePlayerWin(const std::string & player)
-	{
-		makePlayerWinSeveralPoints(player, 4);
-	}
-};
-
-TEST(TennisTests, initialScoreIsZero)
-{
-	CHECK("Love-Love" == game->score());
-}
-
-TEST(TennisTests, playersCanWinSeveralPoints)
-{
-	game->pointTo(Players::PLAYER_ONE);
-	CHECK("Fifteen-Love" == game->score());
-
-	game->pointTo(Players::PLAYER_ONE);
-	CHECK("Thirty-Love" == game->score());
-
-	game->pointTo(Players::PLAYER_ONE);
-	CHECK("Forty-Love" == game->score());
-
-	game->pointTo(Players::PLAYER_TWO);
-	CHECK("Forty-Fifteen" == game->score());
-
-	game->pointTo(Players::PLAYER_TWO);
-	CHECK("Forty-Thirty" == game->score());
-}
-
-TEST(TennisTests, gameIsOverAfterPlayerOneWinsFirstForPoints)
-{
-	makePlayerWin(Players::PLAYER_ONE);
-	CHECK(game->isOver());
-}
-
-TEST(TennisTests, gameIsOverAfterPlayerTwoWinsFirstForPoints)
-{
-	makePlayerWin(Players::PLAYER_TWO);
-	CHECK(game->isOver());
-}
-
-TEST(TennisTests, scoreDoesNotChangeAfterAPlayerWins)
-{
-	makePlayerWin(Players::PLAYER_ONE);
-
-	std::string PLAYER_ONE_WON = Players::PLAYER_ONE + " won!";
-
-	game->pointTo(Players::PLAYER_ONE);
-	CHECK(PLAYER_ONE_WON == game->score());
-
-	game->pointTo(Players::PLAYER_TWO);
-	CHECK(PLAYER_ONE_WON == game->score());
-}
-
-TEST(TennisTests, gameIsNotOverIfNoOneGetsFirstToForty)
-{
-	CHECK(not game->isOver());
-	makePlayerWinSeveralPoints(Players::PLAYER_ONE, 3);
-	CHECK(not game->isOver());
-}
-
-TEST(TennisTests, thereIsDeuce)
-{
-	gameGetToDeuce();
-	CHECK("Deuce" == game->score());
-}
-
-TEST(TennisTests, gameIsNotOverWhenThereIsDeuce)
-{
-	gameGetToDeuce();
-	CHECK(not game->isOver());
-}
-
-TEST(TennisTests, thereIsAdvantage)
-{
-	gameGetToDeuce();
-	game->pointTo(Players::PLAYER_ONE);
-
-	CHECK("Advantage for koko" == game->score());
-}
-
-TEST(TennisTests, backToDeuce)
-{
-	gameGetToDeuce();
-	game->pointTo(Players::PLAYER_ONE);
-	game->pointTo(Players::PLAYER_TWO);
-	CHECK("Deuce" == game->score());
-}
-
-TEST(TennisTests, thePlayerWithAdvantageWins)
-{
-	gameGetToDeuce();
-	game->pointTo(Players::PLAYER_ONE); // Advantage for player one
-	game->pointTo(Players::PLAYER_TWO); // Deuce again
-	game->pointTo(Players::PLAYER_TWO); // Advantage for player two
-	game->pointTo(Players::PLAYER_TWO);
-
-	std::string PLAYER_TWO_WON = Players::PLAYER_TWO + " won!";
-
-	CHECK(PLAYER_TWO_WON == game->score());
-}