From ffaed665b9bb52231b6e3e49f01285f38e7ff1b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6der?= Date: Tue, 21 Oct 2025 15:24:07 +0200 Subject: [PATCH] =?UTF-8?q?Unittest=20f=C3=BCr=20das=20Platzieren=20aller?= =?UTF-8?q?=20W=C3=B6rter=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Start_Linux/unit_tests.c | 33 ++++++++++++++++++++++++++++++++- Start_Mac/unit_tests.c | 30 ++++++++++++++++++++++++++++++ Start_Windows/unit_tests.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Start_Linux/unit_tests.c b/Start_Linux/unit_tests.c index d1a15f5..34b07ed 100644 --- a/Start_Linux/unit_tests.c +++ b/Start_Linux/unit_tests.c @@ -101,7 +101,37 @@ void test_createWordSalad_too_small(void) { } } +void test_createWordSalad_allWordsPlaced() { + char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"}; + char saladHoriz[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + char saladVert[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + + int placed = createWordSalad(saladHoriz, 20, words, 3); + for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) + { + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + saladVert[j][i] = saladHoriz[i][j]; + } + } + + for(int i = 0; i < 3; i++) { + const char* word = words[i]; + int wordFound = 0; + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + const char* row = saladHoriz[j]; + const char* col = saladVert[j]; + wordFound |= strstr(row, word) || strstr(col, word); + } + TEST_ASSERT_TRUE_MESSAGE(wordFound, "Not all words were placed."); + } + + TEST_ASSERT_EQUAL_INT(3, placed); +} + // ---------- Test Setup und TearDown Funktionen ---------- + // Hier Setup- und TearDown-Funktionen definieren, // falls Vor- und Nachbereitungen für die Tests benötigt. @@ -134,9 +164,10 @@ int main(void) { RUN_TEST(test_readWords_empty_file); RUN_TEST(test_createWordSalad_all_fit); RUN_TEST(test_createWordSalad_too_small); + RUN_TEST(test_createWordSalad_allWordsPlaced); int result = UNITY_END(); // Test-Ergebnisse print_test_result(result); return result; -} \ No newline at end of file +} diff --git a/Start_Mac/unit_tests.c b/Start_Mac/unit_tests.c index 50a62cf..34b07ed 100644 --- a/Start_Mac/unit_tests.c +++ b/Start_Mac/unit_tests.c @@ -101,6 +101,35 @@ void test_createWordSalad_too_small(void) { } } +void test_createWordSalad_allWordsPlaced() { + char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"}; + char saladHoriz[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + char saladVert[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + + int placed = createWordSalad(saladHoriz, 20, words, 3); + for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) + { + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + saladVert[j][i] = saladHoriz[i][j]; + } + } + + for(int i = 0; i < 3; i++) { + const char* word = words[i]; + int wordFound = 0; + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + const char* row = saladHoriz[j]; + const char* col = saladVert[j]; + wordFound |= strstr(row, word) || strstr(col, word); + } + TEST_ASSERT_TRUE_MESSAGE(wordFound, "Not all words were placed."); + } + + TEST_ASSERT_EQUAL_INT(3, placed); +} + // ---------- Test Setup und TearDown Funktionen ---------- // Hier Setup- und TearDown-Funktionen definieren, @@ -135,6 +164,7 @@ int main(void) { RUN_TEST(test_readWords_empty_file); RUN_TEST(test_createWordSalad_all_fit); RUN_TEST(test_createWordSalad_too_small); + RUN_TEST(test_createWordSalad_allWordsPlaced); int result = UNITY_END(); // Test-Ergebnisse print_test_result(result); diff --git a/Start_Windows/unit_tests.c b/Start_Windows/unit_tests.c index 50a62cf..34b07ed 100644 --- a/Start_Windows/unit_tests.c +++ b/Start_Windows/unit_tests.c @@ -101,6 +101,35 @@ void test_createWordSalad_too_small(void) { } } +void test_createWordSalad_allWordsPlaced() { + char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"}; + char saladHoriz[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + char saladVert[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN]; + + int placed = createWordSalad(saladHoriz, 20, words, 3); + for(int i = 0; i < MAX_SEARCH_FIELD_LEN; i++) + { + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + saladVert[j][i] = saladHoriz[i][j]; + } + } + + for(int i = 0; i < 3; i++) { + const char* word = words[i]; + int wordFound = 0; + for(int j = 0; j < MAX_SEARCH_FIELD_LEN; j++) + { + const char* row = saladHoriz[j]; + const char* col = saladVert[j]; + wordFound |= strstr(row, word) || strstr(col, word); + } + TEST_ASSERT_TRUE_MESSAGE(wordFound, "Not all words were placed."); + } + + TEST_ASSERT_EQUAL_INT(3, placed); +} + // ---------- Test Setup und TearDown Funktionen ---------- // Hier Setup- und TearDown-Funktionen definieren, @@ -135,6 +164,7 @@ int main(void) { RUN_TEST(test_readWords_empty_file); RUN_TEST(test_createWordSalad_all_fit); RUN_TEST(test_createWordSalad_too_small); + RUN_TEST(test_createWordSalad_allWordsPlaced); int result = UNITY_END(); // Test-Ergebnisse print_test_result(result); -- 2.47.2