From 96183ac1150728d80d3498237105d72dff04abb3 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Thu, 12 Jan 2023 11:09:11 +0100 Subject: [PATCH] player loses round --- src/c/rockPaperScissors.c | 9 +++++++ test/c/test_rockPaperScissors.c | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index a741b51..40a00fe 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -13,15 +13,24 @@ char findWinner(int inputPlayer, int inputComputer){ if (inputComputer == SCISSORS){ return 'p'; } + else if (inputComputer == PAPER){ + return 'c'; + } } else if (inputPlayer == PAPER){ if (inputComputer == ROCK){ return 'p'; } + else if (inputComputer == SCISSORS){ + return 'c'; + } } else if (inputPlayer == SCISSORS){ if (inputComputer == PAPER){ return 'p'; } + else if (inputComputer == ROCK){ + return 'c'; + } } } \ No newline at end of file diff --git a/test/c/test_rockPaperScissors.c b/test/c/test_rockPaperScissors.c index e533bf1..327b2d7 100644 --- a/test/c/test_rockPaperScissors.c +++ b/test/c/test_rockPaperScissors.c @@ -73,6 +73,48 @@ void test_rockPaperScissors_differentResultsPlayerWins(void) TEST_ASSERT_EQUAL_INT('p', result); } +void test_rockPaperScissors_differentResultsPlayerLoses(void) +{ + /* arrange */ + //Hier die Werte eingeben + char result; //p=player, c=computer, n=none + int inputPlayer = ROCK; + int inputComputer = PAPER; + + /* act */ + //Die Funktion wird ausgeführt + result = findWinner(inputPlayer, inputComputer); + + /* assert */ + //Vergleichen + TEST_ASSERT_EQUAL_INT('c', result); + + /* arrange */ + //Hier die Werte eingeben + inputPlayer = PAPER; + inputComputer = SCISSORS; + + /* act */ + //Die Funktion wird ausgeführt + result = findWinner(inputPlayer, inputComputer); + + /* assert */ + //Vergleichen + TEST_ASSERT_EQUAL_INT('c', result); + + /* arrange */ + //Hier die Werte eingeben + inputPlayer = SCISSORS; + inputComputer = ROCK; + + /* act */ + //Die Funktion wird ausgeführt + result = findWinner(inputPlayer, inputComputer); + + /* assert */ + //Vergleichen + TEST_ASSERT_EQUAL_INT('c', result); +} #endif // TEST @@ -83,4 +125,5 @@ rockPaperScissors_differentResultsPlayerLoses rockPaperScissors_playerGetsBestOutOf3 rockPaperScissors_computerGetsBestOutOf3 rockPaperScissors_outputResult +rockPaperScissors_invalidInput */ \ No newline at end of file