Browse Source

generate computer input

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
4da4f238f9
  1. 7
      src/c/rockPaperScissors.c
  2. 6
      src/c/rockPaperScissors.h
  3. 18
      test/c/test_rockPaperScissors.c

7
src/c/rockPaperScissors.c

@ -4,9 +4,12 @@
#include "rockPaperScissors.h"
char getComputerInput(){
int input = rand() % 3;
return input;
}
char findWinner(int inputPlayer, int inputComputer){
if (inputPlayer == inputComputer){
return NOWINNER;
}
@ -22,4 +25,4 @@ char findWinner(int inputPlayer, int inputComputer){
else {
return COMPUTERWINSROUND;
}
}
}

6
src/c/rockPaperScissors.h

@ -13,7 +13,13 @@ enum roundWinner{
NOWINNER
};
enum gameWinner{
PLAYERWINSGAME,
COMPUTERWINSGAME
};
char findWinner(int inputPlayer, int inputComputer);
char getComputerInput();
#endif

18
test/c/test_rockPaperScissors.c

@ -116,12 +116,24 @@ void test_rockPaperScissors_differentResultsPlayerLoses(void)
TEST_ASSERT_EQUAL_INT(COMPUTERWINSROUND, result);
}
void test_rockPaperScissors_generateComputerInput(void)
{
/* arrange */
//Hier die Werte eingeben
char result;
/* act */
//Die Funktion wird ausgeführt
result = getComputerInput();
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result);
}
#endif // TEST
/*Testcases:
rockPaperScissors_sameResult
rockPaperScissors_differentResultsPlayerWins
rockPaperScissors_differentResultsPlayerLoses
rockPaperScissors_playerGetsBestOutOf3
rockPaperScissors_computerGetsBestOutOf3
rockPaperScissors_outputResult

Loading…
Cancel
Save