From 73943582ed2fef7c42d788acef3df763ca71de5f Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 18:55:44 +0100 Subject: [PATCH] =?UTF-8?q?Implementation=20der=20Tests=20f=C3=BCr=20den?= =?UTF-8?q?=20Testfall=20ungueltige=20Parameter=C3=BCbergabe=20bei=20calcu?= =?UTF-8?q?lateWinner()=20+=20Korrektur=20im=20Prodktivcode=20(Einf=C3=BCg?= =?UTF-8?q?en=20von=20Default=20bei=20=C3=A4u=C3=9Ferer=20Switch)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/SchereSteinPapier.c | 6 +++- src/test/c/Tim/test_SchereSteinPapier.c | 38 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/SchereSteinPapier.c b/src/main/c/Tim/SchereSteinPapier.c index 3b71014..12b9735 100644 --- a/src/main/c/Tim/SchereSteinPapier.c +++ b/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) { switch (x) @@ -78,5 +80,7 @@ int calculateWinner(int x, int y) default: return 3; } + default: return 3; } + } \ No newline at end of file diff --git a/src/test/c/Tim/test_SchereSteinPapier.c b/src/test/c/Tim/test_SchereSteinPapier.c index bbe81fe..2b1d348 100644 --- a/src/test/c/Tim/test_SchereSteinPapier.c +++ b/src/test/c/Tim/test_SchereSteinPapier.c @@ -1,5 +1,6 @@ #include "SchereSteinPapier.h" #include "unity.h" +#include void setUp(void) { @@ -88,5 +89,42 @@ void test_Win_USER_Paper_COM_Rock() 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); } \ No newline at end of file