Browse Source

player wins round

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
83699f1a27
  1. 15
      src/c/rockPaperScissors.c
  2. 6
      src/c/rockPaperScissors.h
  3. 46
      test/c/test_rockPaperScissors.c

15
src/c/rockPaperScissors.c

@ -9,4 +9,19 @@ char findWinner(int inputPlayer, int inputComputer){
if (inputPlayer == inputComputer){ if (inputPlayer == inputComputer){
return 'n'; return 'n';
} }
else if (inputPlayer == ROCK){
if (inputComputer == SCISSORS){
return 'p';
}
}
else if (inputPlayer == PAPER){
if (inputComputer == ROCK){
return 'p';
}
}
else if (inputPlayer == SCISSORS){
if (inputComputer == PAPER){
return 'p';
}
}
} }

6
src/c/rockPaperScissors.h

@ -1,6 +1,12 @@
#ifndef ROCKPAPERSCISSORS_H #ifndef ROCKPAPERSCISSORS_H
#define ROCKPAPERSCISSORS_H #define ROCKPAPERSCISSORS_H
enum inputOptions{
ROCK = 1,
PAPER = 2,
SCISSORS = 3
};
char findWinner(int inputPlayer, int inputComputer); char findWinner(int inputPlayer, int inputComputer);
#endif #endif

46
test/c/test_rockPaperScissors.c

@ -18,7 +18,7 @@ void test_rockPaperScissors_sameResult(void)
/* arrange */ /* arrange */
//Hier die Werte eingeben //Hier die Werte eingeben
char result; //p=player, c=computer, n=none char result; //p=player, c=computer, n=none
int inputPlayer = 1;
int inputPlayer = ROCK;
int inputComputer = inputPlayer; int inputComputer = inputPlayer;
/* act */ /* act */
@ -30,6 +30,50 @@ void test_rockPaperScissors_sameResult(void)
TEST_ASSERT_EQUAL_INT('n', result); TEST_ASSERT_EQUAL_INT('n', result);
} }
void test_rockPaperScissors_differentResultsPlayerWins(void)
{
/* arrange */
//Hier die Werte eingeben
char result; //p=player, c=computer, n=none
int inputPlayer = ROCK;
int inputComputer = SCISSORS;
/* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer);
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT('p', result);
/* arrange */
//Hier die Werte eingeben
inputPlayer = PAPER;
inputComputer = ROCK;
/* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer);
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT('p', result);
/* arrange */
//Hier die Werte eingeben
inputPlayer = SCISSORS;
inputComputer = PAPER;
/* act */
//Die Funktion wird ausgeführt
result = findWinner(inputPlayer, inputComputer);
/* assert */
//Vergleichen
TEST_ASSERT_EQUAL_INT('p', result);
}
#endif // TEST #endif // TEST
/*Testcases: /*Testcases:

Loading…
Cancel
Save