From 4bc6f7965ff937ca45403fc1650605e0e5c28a75 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Mon, 23 Jan 2023 10:10:57 +0100 Subject: [PATCH] player input is invalid --- src/c/rockPaperScissors.c | 5 ++++- test/c/test_rockPaperScissors.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index a8477e6..7a98a97 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -44,8 +44,11 @@ int wasGameWon(roundsToWin, playerWins, computerWins){ bool validatePlayerInput(int playerInput){ bool inputValid; - if (playerInput == ROCK || PAPER || SCISSORS){ + if (playerInput == ROCK || playerInput == PAPER || playerInput == SCISSORS){ inputValid = true; } + else { + inputValid = false; + } return inputValid; } \ No newline at end of file diff --git a/test/c/test_rockPaperScissors.c b/test/c/test_rockPaperScissors.c index 69d6761..5b492e4 100644 --- a/test/c/test_rockPaperScissors.c +++ b/test/c/test_rockPaperScissors.c @@ -187,7 +187,7 @@ void test_rockPaperScissors_validPlayerInput(void) /* arrange */ //Hier die Werte eingeben bool result; - int playerInput = 1; + int playerInput = 2; /* act */ //Die Funktion wird ausgeführt @@ -198,6 +198,22 @@ void test_rockPaperScissors_validPlayerInput(void) TEST_ASSERT_EQUAL_INT(true, result); } +void test_rockPaperScissors_invalidPlayerInput(void) +{ + /* arrange */ + //Hier die Werte eingeben + bool result; + int playerInput = 5; + + /* act */ + //Die Funktion wird ausgeführt + result = validatePlayerInput(playerInput); + + /* assert */ + //Vergleichen + TEST_ASSERT_EQUAL_INT(false, result); +} + #endif // TEST /*Testcases: