Browse Source

refactoring: Einheitliche Benennung der Test, Strukturierung nach Testfällen und Kommentierung der Tests

remotes/origin/tim
fdai7727 11 months ago
parent
commit
8c90131f90
  1. 118
      src/test/c/Tim/test_SchereSteinPapier.c

118
src/test/c/Tim/test_SchereSteinPapier.c

@ -12,119 +12,147 @@ void tearDown(void)
} }
void test_drawScissorScissor()
//Testfälle für Unentschieden
//1. Beide wählen Schere
void test_draw_USER_Scissor_COM_Scissor()
{ {
//arrange
int expectedResult = 0; int expectedResult = 0;
//act
int actualResult = calculateWinner(1,1); int actualResult = calculateWinner(1,1);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_drawRockRock()
//2. Beide wählen Stein
void test_draw_USER_Rock_COM_Rock()
{ {
//arrange
int expectedResult = 0; int expectedResult = 0;
//act
int actualResult = calculateWinner(2,2); int actualResult = calculateWinner(2,2);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_drawPaperPaper()
//3. Beide wählen Papier
void test_draw_USER_Paper_COM_Paper()
{ {
//arrange
int expectedResult = 0; int expectedResult = 0;
//act
int actualResult = calculateWinner(3,3); int actualResult = calculateWinner(3,3);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
//Testfälle für Niederlage
//1. User wählt Schere, Computer wählt Stein
void test_lose_USER_Scissor_COM_Rock() void test_lose_USER_Scissor_COM_Rock()
{ {
//arrange
int expectedResult = -1; int expectedResult = -1;
//act
int actualResult = calculateWinner(1,2); int actualResult = calculateWinner(1,2);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
//2. User wählt Papier, Computer wählt Schere
void test_lose_USER_Paper_COM_Scissor() void test_lose_USER_Paper_COM_Scissor()
{ {
//arrange
int expectedResult = -1; int expectedResult = -1;
//act
int actualResult = calculateWinner(3,1); int actualResult = calculateWinner(3,1);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
//3. User wählt Stein, Computer wählt Papier
void test_lose_USER_Rock_COM_Paper() void test_lose_USER_Rock_COM_Paper()
{ {
//arrange
int expectedResult = -1; int expectedResult = -1;
//act
int actualResult = calculateWinner(2,3); int actualResult = calculateWinner(2,3);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_Win_USER_Scissor_COM_Paper()
//Testfälle für Sieg
//1. User wählt Schere, Computer wählt Papier
void test_win_USER_Scissor_COM_Paper()
{ {
//arrange
int expectedResult = 1; int expectedResult = 1;
//act
int actualResult = calculateWinner(1,3); int actualResult = calculateWinner(1,3);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_Win_USER_Rock_COM_Scissor()
//2. User wählt Stein, Computer wählt Schere
void test_win_USER_Rock_COM_Scissor()
{ {
//arrange
int expectedResult = 1; int expectedResult = 1;
//act
int actualResult = calculateWinner(2,1); int actualResult = calculateWinner(2,1);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_Win_USER_Paper_COM_Rock()
//3. User wählt Papier, Computer wählt Stein
void test_win_USER_Paper_COM_Rock()
{ {
//arrange
int expectedResult = 1; int expectedResult = 1;
//act
int actualResult = calculateWinner(3,2); int actualResult = calculateWinner(3,2);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_USER_unknownParameter_Rock_randomChoice()
//Testfälle für ungültige Parameterübergabe
//1. Durch den User wurde ein ungültiges Parameter übergeben
// Der Computer wählt eine Zahl zwischen 1 und 3
void test_error_USER_unknownParameter_Rock_randomChoice()
{ {
//arrange
int expectedResult = 3; int expectedResult = 3;
//act
int actualResult = calculateWinner(5,rand() % 3 + 1); int actualResult = calculateWinner(5,rand() % 3 + 1);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_USER_randomChoice_Rock_unknownParameter()
//2. Der User wählt eine Zahl zwischen 1 und 3
// Durch den Computer wurde ein ungültiges Parameter übergeben
void test_error_USER_randomChoice_Rock_unknownParameter()
{ {
//arrange
int expectedResult = 3; int expectedResult = 3;
//act
int actualResult = calculateWinner(rand() % 3 + 1, 5); int actualResult = calculateWinner(rand() % 3 + 1, 5);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_USER_randomChoice_Rock_zero()
//3. Der User wählt eine Zahl zwischen 1 und 3
// Durch den Computer wurde das ungültige Parameter 0 übergeben
void test_error_USER_randomChoice_Rock_zero()
{ {
//arrange
int expectedResult = 3; int expectedResult = 3;
//act
int actualResult = calculateWinner(rand() % 3 + 1, 0); int actualResult = calculateWinner(rand() % 3 + 1, 0);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
void test_USER_zero_Rock_randomChoice()
//4. Durch den User wurde das ungültige Parameter 0 übergeben
// Der Computer wählt eine Zahl zwischen 1 und 3
void test_error_USER_zero_Rock_randomChoice()
{ {
//arrange
int expectedResult = 3; int expectedResult = 3;
//act
int actualResult = calculateWinner(0, rand() % 3 + 1); int actualResult = calculateWinner(0, rand() % 3 + 1);
//assert
TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); TEST_ASSERT_EQUAL_INT(expectedResult, actualResult);
} }
Loading…
Cancel
Save