Browse Source

Player input is valid

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
d213df6de3
  1. 8
      src/c/rockPaperScissors.c
  2. 5
      src/c/rockPaperScissors.h
  3. 18
      test/c/test_rockPaperScissors.c

8
src/c/rockPaperScissors.c

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "rockPaperScissors.h"
@ -41,3 +42,10 @@ int wasGameWon(roundsToWin, playerWins, computerWins){
return winner;
}
bool validatePlayerInput(int playerInput){
bool inputValid;
if (playerInput == ROCK || PAPER || SCISSORS){
inputValid = true;
}
return inputValid;
}

5
src/c/rockPaperScissors.h

@ -1,6 +1,8 @@
#ifndef ROCKPAPERSCISSORS_H
#define ROCKPAPERSCISSORS_H
#include <stdbool.h>
enum inputOptions{
ROCK,
PAPER,
@ -22,6 +24,7 @@ enum gameWinner{
int findWinner(int inputPlayer, int inputComputer);
int getComputerInput();
int wasGameWon(roundsToWin, playerWins, computerWins);
int wasGameWon(int roundsToWin, int playerWins, int computerWins);
bool validatePlayerInput(int playerInput);
#endif

18
test/c/test_rockPaperScissors.c

@ -182,11 +182,25 @@ void test_rockPaperScissors_gameWasNotWon(void)
TEST_ASSERT_EQUAL_INT(NOTWONYET, result);
}
void test_rockPaperScissors_validPlayerInput(void)
{
/* arrange */
//Hier die Werte eingeben
bool result;
int playerInput = 1;
/* act */
//Die Funktion wird ausgeführt
result = validatePlayerInput(playerInput);
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT(true, result);
}
#endif // TEST
/*Testcases:
rockPaperScissors_playerGetsBestOutOf3
rockPaperScissors_computerGetsBestOutOf3
rockPaperScissors_outputResult
rockPaperScissors_invalidInput
*/
Loading…
Cancel
Save