Browse Source

Erweiterung der Test für getWordFromList für Index über und unter Wortliste + Anpassung im Produktivcode

remotes/origin/tim
fdai7727 11 months ago
parent
commit
43abfa0aa1
  1. 2
      src/main/c/Tim/hangman.c
  2. 14
      src/test/c/Tim/test_hangman.c

2
src/main/c/Tim/hangman.c

@ -139,7 +139,7 @@ void getWelcomeMessageHangman()
char* getWordFromList(int x) char* getWordFromList(int x)
{ {
if(x<LISTSIZE)
if(x>=0 && x<LISTSIZE)
{ {
return wordlist[x]; return wordlist[x];
} }

14
src/test/c/Tim/test_hangman.c

@ -40,7 +40,18 @@ void test_getWordFromList_Kleiderschrank_5()
} }
void test_getWordFromList_IndexOutOfList()
void test_getWordFromList_Index_lower_Listsize()
{
//arrange
int pos = -5;
char expectedResult[] = "Index nicht vorhanden";
//act
char actualResult[30];
strcpy(actualResult,getWordFromList(pos));
//assert
TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult);
}
void test_getWordFromList_Index_higher_Listsize()
{ {
//arrange //arrange
int pos = LISTSIZE+1; int pos = LISTSIZE+1;
@ -52,6 +63,7 @@ void test_getWordFromList_IndexOutOfList()
TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult);
} }
void test_wonGame_wordGuessed() void test_wonGame_wordGuessed()
{ {
//arrange //arrange

Loading…
Cancel
Save