From c166123a0048eced96d43669f649506a578e15be Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Tue, 24 Jan 2023 13:36:18 +0100 Subject: [PATCH] improved random numbers --- src/c/rockPaperScissors.c | 2 ++ src/c/rockPaperScissors.h | 3 +++ test/c/test_rockPaperScissors.c | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 14fb1cf..3de9aaf 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "rockPaperScissors.h" @@ -56,6 +57,7 @@ bool validatePlayerInput(int playerInput){ int getComputerInput(){ + srand(rand() % 300); int input = rand() % 3; return input; } diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index 3c655e2..c35397c 100644 --- a/src/c/rockPaperScissors.h +++ b/src/c/rockPaperScissors.h @@ -28,5 +28,8 @@ int wasGameWon(int roundsToWin, int playerWins, int computerWins); bool validatePlayerInput(int playerInput); int getPlayerInput(); int playRockPaperScissors(int rounds); +void printPrompt(int roundsToWin); +void printResult(int playerInput, int computerInput, int roundWinner, int playerWins, int computerWins); +void printWinner(int winner); #endif \ No newline at end of file diff --git a/test/c/test_rockPaperScissors.c b/test/c/test_rockPaperScissors.c index 0336bde..b6ba580 100644 --- a/test/c/test_rockPaperScissors.c +++ b/test/c/test_rockPaperScissors.c @@ -31,7 +31,7 @@ void test_rockPaperScissors_playerWinsRound(void) { /* arrange */ int result; - + int inputPlayer = ROCK; int inputComputer = SCISSORS; @@ -111,7 +111,7 @@ void test_rockPaperScissors_generateComputerInput(void) result = getComputerInput(); /* assert */ - TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result); + TEST_ASSERT_INT_WITHIN(1, 1, result); }