diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 29b6ed5..40598d7 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -4,12 +4,12 @@ #include "rockPaperScissors.h" -char getComputerInput(){ +int getComputerInput(){ int input = rand() % 3; return input; } -char findWinner(int inputPlayer, int inputComputer){ +int findWinner(int inputPlayer, int inputComputer){ if (inputPlayer == inputComputer){ 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){ winner = PLAYERWINSGAME; } + else if (computerWins == roundsToWin){ + winner = COMPUTERWINSGAME; + } return winner; } diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index 611fcf6..e3eb73f 100644 --- a/src/c/rockPaperScissors.h +++ b/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 \ No newline at end of file diff --git a/test/c/test_rockPaperScissors.c b/test/c/test_rockPaperScissors.c index ac07ab9..eb74c62 100644 --- a/test/c/test_rockPaperScissors.c +++ b/test/c/test_rockPaperScissors.c @@ -17,7 +17,7 @@ void test_rockPaperScissors_sameResult(void) { /* arrange */ //Hier die Werte eingeben - char result; + int result; int inputPlayer = ROCK; int inputComputer = inputPlayer; @@ -34,7 +34,7 @@ void test_rockPaperScissors_differentResultsPlayerWins(void) { /* arrange */ //Hier die Werte eingeben - char result; + int result; int inputPlayer = ROCK; int inputComputer = SCISSORS; @@ -77,7 +77,7 @@ void test_rockPaperScissors_differentResultsPlayerLoses(void) { /* arrange */ //Hier die Werte eingeben - char result; + int result; int inputPlayer = ROCK; int inputComputer = PAPER; @@ -120,7 +120,7 @@ void test_rockPaperScissors_generateComputerInput(void) { /* arrange */ //Hier die Werte eingeben - char result; + int result; /* act */ //Die Funktion wird ausgeführt @@ -135,7 +135,7 @@ void test_rockPaperScissors_playerGetsBestOutOf3(void) { /* arrange */ //Hier die Werte eingeben - char result; + int result; int roundsToWin = 2; int playerWins = 2, computerWins = 1; @@ -148,6 +148,23 @@ void test_rockPaperScissors_playerGetsBestOutOf3(void) 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 /*Testcases: