From 793c94a2149a38dedaa951d9baa68a79087898d4 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Sun, 15 Jan 2023 17:04:52 +0100 Subject: [PATCH] player wins game --- src/c/rockPaperScissors.c | 9 +++++++++ src/c/rockPaperScissors.h | 4 +++- test/c/test_rockPaperScissors.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 240f0ec..29b6ed5 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -26,3 +26,12 @@ char findWinner(int inputPlayer, int inputComputer){ return COMPUTERWINSROUND; } } + +char wasGameWon(roundsToWin, playerWins, computerWins){ + char winner; + if (playerWins == roundsToWin){ + winner = PLAYERWINSGAME; + } + return winner; +} + diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index e31dbcd..611fcf6 100644 --- a/src/c/rockPaperScissors.h +++ b/src/c/rockPaperScissors.h @@ -15,11 +15,13 @@ enum roundWinner{ enum gameWinner{ PLAYERWINSGAME, - COMPUTERWINSGAME + COMPUTERWINSGAME, + NOTWONYET }; char findWinner(int inputPlayer, int inputComputer); char getComputerInput(); +char 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 141ebb8..ac07ab9 100644 --- a/test/c/test_rockPaperScissors.c +++ b/test/c/test_rockPaperScissors.c @@ -131,6 +131,23 @@ void test_rockPaperScissors_generateComputerInput(void) 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 /*Testcases: