From 83699f1a2708663c8ebe6d42c2b08a935b7010b3 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Wed, 11 Jan 2023 21:06:15 +0100 Subject: [PATCH] player wins round --- src/c/rockPaperScissors.c | 15 +++++++++++ src/c/rockPaperScissors.h | 6 +++++ test/c/test_rockPaperScissors.c | 46 ++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 2a1b239..a741b51 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -9,4 +9,19 @@ char findWinner(int inputPlayer, int inputComputer){ if (inputPlayer == inputComputer){ 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'; + } + } } \ No newline at end of file diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index 4531af5..7ce0730 100644 --- a/src/c/rockPaperScissors.h +++ b/src/c/rockPaperScissors.h @@ -1,6 +1,12 @@ #ifndef ROCKPAPERSCISSORS_H #define ROCKPAPERSCISSORS_H +enum inputOptions{ + ROCK = 1, + PAPER = 2, + SCISSORS = 3 + }; + char findWinner(int inputPlayer, int inputComputer); #endif \ No newline at end of file diff --git a/test/c/test_rockPaperScissors.c b/test/c/test_rockPaperScissors.c index fd2745e..e533bf1 100644 --- a/test/c/test_rockPaperScissors.c +++ b/test/c/test_rockPaperScissors.c @@ -18,7 +18,7 @@ void test_rockPaperScissors_sameResult(void) /* arrange */ //Hier die Werte eingeben char result; //p=player, c=computer, n=none - int inputPlayer = 1; + int inputPlayer = ROCK; int inputComputer = inputPlayer; /* act */ @@ -30,6 +30,50 @@ void test_rockPaperScissors_sameResult(void) 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 /*Testcases: