Browse Source

Implementation der Tests für den Testfall ungueltige Parameterübergabe bei calculateWinner() + Korrektur im Prodktivcode (Einfügen von Default bei äußerer Switch)

remotes/origin/tim
fdai7727 11 months ago
parent
commit
73943582ed
  1. 6
      src/main/c/Tim/SchereSteinPapier.c
  2. 38
      src/test/c/Tim/test_SchereSteinPapier.c

6
src/main/c/Tim/SchereSteinPapier.c

@ -43,7 +43,9 @@ void schereSteinPapier()
} }
} }
//Berechnung,welche Auswahl gewinnt.
//@return: 0 = unentschieden; 1 = gewonnen; -1 = verloren; 3 = Fehler bei der Wertübergabe
//@param x = UserChoice; y = COMChoice
int calculateWinner(int x, int y) int calculateWinner(int x, int y)
{ {
switch (x) switch (x)
@ -78,5 +80,7 @@ int calculateWinner(int x, int y)
default: return 3; default: return 3;
} }
default: return 3;
} }
} }

38
src/test/c/Tim/test_SchereSteinPapier.c

@ -1,5 +1,6 @@
#include "SchereSteinPapier.h" #include "SchereSteinPapier.h"
#include "unity.h" #include "unity.h"
#include <stdlib.h>
void setUp(void) void setUp(void)
{ {
@ -88,5 +89,42 @@ void test_Win_USER_Paper_COM_Rock()
int actualResult = calculateWinner(3,2); int actualResult = calculateWinner(3,2);
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
}
void test_USER_unknownParameter_Rock_randomChoice()
{
int expectedResult = 3;
int actualResult = calculateWinner(5,rand() % 3 + 1);
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
}
void test_USER_randomChoice_Rock_unknownParameter()
{
int expectedResult = 3;
int actualResult = calculateWinner(rand() % 3 + 1, 5);
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
}
void test_USER_randomChoice_Rock_zero()
{
int expectedResult = 3;
int actualResult = calculateWinner(rand() % 3 + 1, 0);
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
}
void test_USER_zero_Rock_randomChoice()
{
int expectedResult = 3;
int actualResult = calculateWinner(0, rand() % 3 + 1);
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
Loading…
Cancel
Save