Browse Source

refactoring: improved testnames + removed comments

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
852c84e0a3
  1. 71
      test/c/test_rockPaperScissors.c

71
test/c/test_rockPaperScissors.c

@ -1,6 +1,5 @@
#ifdef TEST #ifdef TEST
#include "unity.h" #include "unity.h"
//in example.h wird die Funktion deklariert
#include "rockPaperScissors.h" #include "rockPaperScissors.h"
//Vor- bzw. Nachbereitung //Vor- bzw. Nachbereitung
@ -12,205 +11,179 @@ void tearDown(void)
{ {
} }
//Hier läuft der Test
void test_rockPaperScissors_sameResult(void) void test_rockPaperScissors_sameResult(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
int inputPlayer = ROCK; int inputPlayer = ROCK;
int inputComputer = inputPlayer; int inputComputer = inputPlayer;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(NOWINNER, result); TEST_ASSERT_EQUAL_INT(NOWINNER, result);
} }
void test_rockPaperScissors_differentResultsPlayerWins(void)
void test_rockPaperScissors_playerWinsRound(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
int inputPlayer = ROCK; int inputPlayer = ROCK;
int inputComputer = SCISSORS; int inputComputer = SCISSORS;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(PLAYERWINSROUND, result); TEST_ASSERT_EQUAL_INT(PLAYERWINSROUND, result);
/* arrange */
//Hier die Werte eingeben
/* arrange */
inputPlayer = PAPER; inputPlayer = PAPER;
inputComputer = ROCK; inputComputer = ROCK;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(PLAYERWINSROUND, result); TEST_ASSERT_EQUAL_INT(PLAYERWINSROUND, result);
/* arrange */
//Hier die Werte eingeben
/* arrange */
inputPlayer = SCISSORS; inputPlayer = SCISSORS;
inputComputer = PAPER; inputComputer = PAPER;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(PLAYERWINSROUND, result); TEST_ASSERT_EQUAL_INT(PLAYERWINSROUND, result);
} }
void test_rockPaperScissors_differentResultsPlayerLoses(void)
void test_rockPaperScissors_computerWinsRound(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
int inputPlayer = ROCK; int inputPlayer = ROCK;
int inputComputer = PAPER; int inputComputer = PAPER;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result); TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result);
/* arrange */
//Hier die Werte eingeben
/* arrange */
inputPlayer = PAPER; inputPlayer = PAPER;
inputComputer = SCISSORS; inputComputer = SCISSORS;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result); TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result);
/* arrange */
//Hier die Werte eingeben
/* arrange */
inputPlayer = SCISSORS; inputPlayer = SCISSORS;
inputComputer = ROCK; inputComputer = ROCK;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer); result = findWinner(inputPlayer, inputComputer);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result); TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result);
} }
void test_rockPaperScissors_generateComputerInput(void) void test_rockPaperScissors_generateComputerInput(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = getComputerInput(); result = getComputerInput();
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result); TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result);
} }
void test_rockPaperScissors_playerGetsBestOutOf3(void)
void test_rockPaperScissors_playerWinsGame(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
int roundsToWin = 2; int roundsToWin = 2;
int playerWins = 2, computerWins = 1; int playerWins = 2, computerWins = 1;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = wasGameWon(roundsToWin, playerWins, computerWins); result = wasGameWon(roundsToWin, playerWins, computerWins);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(PLAYERWINSGAME, result); TEST_ASSERT_EQUAL_INT(PLAYERWINSGAME, result);
} }
void test_rockPaperScissors_computerGetsBestOutOf3(void)
void test_rockPaperScissors_computerWinsGame(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
int roundsToWin = 2; int roundsToWin = 2;
int playerWins = 1, computerWins = 2; int playerWins = 1, computerWins = 2;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = wasGameWon(roundsToWin, playerWins, computerWins); result = wasGameWon(roundsToWin, playerWins, computerWins);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(COMPUTERWINSGAME, result); TEST_ASSERT_EQUAL_INT(COMPUTERWINSGAME, result);
} }
void test_rockPaperScissors_gameWasNotWon(void) void test_rockPaperScissors_gameWasNotWon(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
int result; int result;
int roundsToWin = 2; int roundsToWin = 2;
int playerWins = 1, computerWins = 1; int playerWins = 1, computerWins = 1;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = wasGameWon(roundsToWin, playerWins, computerWins); result = wasGameWon(roundsToWin, playerWins, computerWins);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(NOTWONYET, result); TEST_ASSERT_EQUAL_INT(NOTWONYET, result);
} }
void test_rockPaperScissors_validPlayerInput(void) void test_rockPaperScissors_validPlayerInput(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
bool result; bool result;
int playerInput = 2; int playerInput = 2;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = validatePlayerInput(playerInput); result = validatePlayerInput(playerInput);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(true, result); TEST_ASSERT_EQUAL_INT(true, result);
} }
void test_rockPaperScissors_invalidPlayerInput(void) void test_rockPaperScissors_invalidPlayerInput(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben
bool result; bool result;
int playerInput = 5; int playerInput = 5;
/* act */ /* act */
//Die Funktion wird ausgeführt
result = validatePlayerInput(playerInput); result = validatePlayerInput(playerInput);
/* assert */ /* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(false, result); TEST_ASSERT_EQUAL_INT(false, result);
} }
Loading…
Cancel
Save