Browse Source

player wins game

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
793c94a214
  1. 9
      src/c/rockPaperScissors.c
  2. 4
      src/c/rockPaperScissors.h
  3. 17
      test/c/test_rockPaperScissors.c

9
src/c/rockPaperScissors.c

@ -26,3 +26,12 @@ char findWinner(int inputPlayer, int inputComputer){
return COMPUTERWINSROUND; return COMPUTERWINSROUND;
} }
} }
char wasGameWon(roundsToWin, playerWins, computerWins){
char winner;
if (playerWins == roundsToWin){
winner = PLAYERWINSGAME;
}
return winner;
}

4
src/c/rockPaperScissors.h

@ -15,11 +15,13 @@ enum roundWinner{
enum gameWinner{ enum gameWinner{
PLAYERWINSGAME, PLAYERWINSGAME,
COMPUTERWINSGAME
COMPUTERWINSGAME,
NOTWONYET
}; };
char findWinner(int inputPlayer, int inputComputer); char findWinner(int inputPlayer, int inputComputer);
char getComputerInput(); char getComputerInput();
char wasGameWon(roundsToWin, playerWins, computerWins);
#endif #endif

17
test/c/test_rockPaperScissors.c

@ -131,6 +131,23 @@ void test_rockPaperScissors_generateComputerInput(void)
TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result); TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result);
} }
void test_rockPaperScissors_playerGetsBestOutOf3(void)
{
/* arrange */
//Hier die Werte eingeben
char result;
int roundsToWin = 2;
int playerWins = 2, computerWins = 1;
/* act */
//Die Funktion wird ausgeführt
result = wasGameWon(roundsToWin, playerWins, computerWins);
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(PLAYERWINSGAME, result);
}
#endif // TEST #endif // TEST
/*Testcases: /*Testcases:

Loading…
Cancel
Save