Browse Source

computer wins game

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
4354c80aab
  1. 11
      src/c/rockPaperScissors.c
  2. 6
      src/c/rockPaperScissors.h
  3. 27
      test/c/test_rockPaperScissors.c

11
src/c/rockPaperScissors.c

@ -4,12 +4,12 @@
#include "rockPaperScissors.h" #include "rockPaperScissors.h"
char getComputerInput(){
int getComputerInput(){
int input = rand() % 3; int input = rand() % 3;
return input; return input;
} }
char findWinner(int inputPlayer, int inputComputer){
int findWinner(int inputPlayer, int inputComputer){
if (inputPlayer == inputComputer){ if (inputPlayer == inputComputer){
return NOWINNER; return NOWINNER;
} }
@ -27,11 +27,14 @@ char findWinner(int inputPlayer, int inputComputer){
} }
} }
char wasGameWon(roundsToWin, playerWins, computerWins){
char winner;
int wasGameWon(roundsToWin, playerWins, computerWins){
int winner;
if (playerWins == roundsToWin){ if (playerWins == roundsToWin){
winner = PLAYERWINSGAME; winner = PLAYERWINSGAME;
} }
else if (computerWins == roundsToWin){
winner = COMPUTERWINSGAME;
}
return winner; return winner;
} }

6
src/c/rockPaperScissors.h

@ -20,8 +20,8 @@ enum gameWinner{
}; };
char findWinner(int inputPlayer, int inputComputer);
char getComputerInput();
char wasGameWon(roundsToWin, playerWins, computerWins);
int findWinner(int inputPlayer, int inputComputer);
int getComputerInput();
int wasGameWon(roundsToWin, playerWins, computerWins);
#endif #endif

27
test/c/test_rockPaperScissors.c

@ -17,7 +17,7 @@ void test_rockPaperScissors_sameResult(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben //Hier die Werte eingeben
char result;
int result;
int inputPlayer = ROCK; int inputPlayer = ROCK;
int inputComputer = inputPlayer; int inputComputer = inputPlayer;
@ -34,7 +34,7 @@ void test_rockPaperScissors_differentResultsPlayerWins(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben //Hier die Werte eingeben
char result;
int result;
int inputPlayer = ROCK; int inputPlayer = ROCK;
int inputComputer = SCISSORS; int inputComputer = SCISSORS;
@ -77,7 +77,7 @@ void test_rockPaperScissors_differentResultsPlayerLoses(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben //Hier die Werte eingeben
char result;
int result;
int inputPlayer = ROCK; int inputPlayer = ROCK;
int inputComputer = PAPER; int inputComputer = PAPER;
@ -120,7 +120,7 @@ void test_rockPaperScissors_generateComputerInput(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben //Hier die Werte eingeben
char result;
int result;
/* act */ /* act */
//Die Funktion wird ausgeführt //Die Funktion wird ausgeführt
@ -135,7 +135,7 @@ void test_rockPaperScissors_playerGetsBestOutOf3(void)
{ {
/* arrange */ /* arrange */
//Hier die Werte eingeben //Hier die Werte eingeben
char result;
int result;
int roundsToWin = 2; int roundsToWin = 2;
int playerWins = 2, computerWins = 1; int playerWins = 2, computerWins = 1;
@ -148,6 +148,23 @@ void test_rockPaperScissors_playerGetsBestOutOf3(void)
TEST_ASSERT_EQUAL_INT(PLAYERWINSGAME, result); TEST_ASSERT_EQUAL_INT(PLAYERWINSGAME, result);
} }
void test_rockPaperScissors_computerGetsBestOutOf3(void)
{
/* arrange */
//Hier die Werte eingeben
int result;
int roundsToWin = 2;
int playerWins = 1, computerWins = 2;
/* act */
//Die Funktion wird ausgeführt
result = wasGameWon(roundsToWin, playerWins, computerWins);
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(COMPUTERWINSGAME, result);
}
#endif // TEST #endif // TEST
/*Testcases: /*Testcases:

Loading…
Cancel
Save