Author SHA1 Message Date
schroederen ffaed665b9 Unittest für das Platzieren aller Wörter hinzugefügt. 2025-10-21 15:24:07 +02:00
schroederen e20bf82c19 Makefile angepasst 2025-10-21 11:45:37 +02:00
schroederen 1ed03a3444 Windows Makefile korrigiert 2025-10-21 11:24:14 +02:00
schroederen 6b435cf82d Fix makefiles. 2025-10-20 14:39:05 +02:00
11 changed files with 106 additions and 61 deletions
+3 -3
View File
@@ -1,9 +1,9 @@
CC = gcc CC = gcc
CFLAGS = -g -Wall -I$(raylibfolder) CFLAGS = -g -Wall
LDFLAGS = -lGL -lX11 -lm LDFLAGS = -lGL -lX11 -lm
BINARIES = ./linux BINARIES = ./linux
raylib_folder = ./raylib raylibfolder = ./raylib
unityfolder = ./unity unityfolder = ./unity
# -------------------------- # --------------------------
@@ -28,7 +28,7 @@ game.o: game.c
$(CC) $(CFLAGS) -c game.c $(CC) $(CFLAGS) -c game.c
graphicalGame.o: graphicalGame.c graphicalGame.o: graphicalGame.c
$(CC) $(CFLAGS) -c graphicalGame.c $(CC) $(CFLAGS) -I$(raylibfolder) -c graphicalGame.c
# -------------------------- # --------------------------
# Unit Tests # Unit Tests
+32 -1
View File
@@ -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 ---------- // ---------- Test Setup und TearDown Funktionen ----------
// Hier Setup- und TearDown-Funktionen definieren, // Hier Setup- und TearDown-Funktionen definieren,
// falls Vor- und Nachbereitungen für die Tests benötigt. // 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_readWords_empty_file);
RUN_TEST(test_createWordSalad_all_fit); RUN_TEST(test_createWordSalad_all_fit);
RUN_TEST(test_createWordSalad_too_small); RUN_TEST(test_createWordSalad_too_small);
RUN_TEST(test_createWordSalad_allWordsPlaced);
int result = UNITY_END(); // Test-Ergebnisse int result = UNITY_END(); // Test-Ergebnisse
print_test_result(result); print_test_result(result);
return result; return result;
} }
+2 -35
View File
@@ -4,42 +4,9 @@
// TODO: // TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
/**
* @param file Zeiger auf die geöffnete Datei
* @param words 2D-Array zum Speichern der Wörter
* @param maxWordCount Maximale Anzahl von Wörtern, die eingelesen werden sollen
* @return Anzahl der eingelesenen Wörter
*/
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
// ERLEDIGT
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
if (file == NULL || words == NULL || maxWordCount == 0) {
return 0;
}
int wordCount = 0;
char line[MAX_LINE_LEN];
// Zeilen einlesen
while (wordCount < maxWordCount && fgets(line, MAX_LINE_LEN, file) != NULL) {
// Zeile in Wörter aufteilen (Trennzeichen: Leerzeichen, Komma, Semikolon, Newline)
char *token = strtok(line, " ,;\t\n\r");
while (token != NULL && wordCount < maxWordCount) {
// Prüfen ob Token nicht leer ist
if (strlen(token) > 0 && strlen(token) < MAX_WORD_LEN) {
// Wort kopieren und in Großbuchstaben umwandeln
strcpy(words[wordCount], token);
for (int i = 0; words[wordCount][i] != '\0'; i++) {
words[wordCount][i] = toupper((unsigned char)words[wordCount][i]);
}
wordCount++;
}
// Nächstes Wort
token = strtok(NULL, " ,;\t\n\r");
}
}
return wordCount;
} }
Binary file not shown.
+3 -15
View File
@@ -37,22 +37,10 @@ int main(int argc, char *argv[])
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO: // TODO:
// Check if all words were successfully placed // Check if all words were successfully placed
if(placedWords == wordCount) // Start the game if successful
{ // error message if some words couldn't be placed
// Start the game if successful
printf("All %u words were successfully placed in the word salad!\n", wordCount);
createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
showWordSalad(wordSalad, SALAD_SIZE);
}
else
{
// Error message if some words couldn't be placed
fprintf(stderr, "Error: Only %u out of %u words could be placed in the word salad.\n",
placedWords, wordCount);
exitCode = EXIT_FAILURE;
}
} }
else else
{ {
+2 -2
View File
@@ -4,7 +4,7 @@ LDFLAGS = -framework OpenGL -framework CoreFoundation -framework CoreGraphics -f
ARCH := $(shell uname -m) ARCH := $(shell uname -m)
BINARIES = ./macos-$(ARCH) BINARIES = ./macos-$(ARCH)
raylib_folder = ./raylib raylibfolder = ./raylib
unityfolder = ./unity unityfolder = ./unity
# -------------------------- # --------------------------
@@ -43,4 +43,4 @@ test: input.o game.o unit_tests.c $(BINARIES)/libunity.a
# Clean # Clean
# -------------------------- # --------------------------
clean: clean:
rm -f *.o wordsalad rm -f *.o wordsalad $(TEST_BIN)
Binary file not shown.
+30
View File
@@ -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 ---------- // ---------- Test Setup und TearDown Funktionen ----------
// Hier Setup- und TearDown-Funktionen definieren, // Hier Setup- und TearDown-Funktionen definieren,
@@ -135,6 +164,7 @@ int main(void) {
RUN_TEST(test_readWords_empty_file); RUN_TEST(test_readWords_empty_file);
RUN_TEST(test_createWordSalad_all_fit); RUN_TEST(test_createWordSalad_all_fit);
RUN_TEST(test_createWordSalad_too_small); RUN_TEST(test_createWordSalad_too_small);
RUN_TEST(test_createWordSalad_allWordsPlaced);
int result = UNITY_END(); // Test-Ergebnisse int result = UNITY_END(); // Test-Ergebnisse
print_test_result(result); print_test_result(result);
Binary file not shown.
+4 -5
View File
@@ -1,9 +1,9 @@
CC = gcc CC = gcc
CFLAGS = -g -Wall -I$(raylibfolder) CFLAGS = -g -Wall
LDFLAGS = -lopengl32 -lgdi32 -lwinmm LDFLAGS = -lopengl32 -lgdi32 -lwinmm
BINARIES = ./windows BINARIES = ./windows
raylib_folder = ./raylib raylibfolder = ./raylib
unityfolder = ./unity unityfolder = ./unity
# -------------------------- # --------------------------
@@ -12,7 +12,6 @@ unityfolder = ./unity
wordsalad_initial: wordsalad_initial:
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
# -------------------------- # --------------------------
# Normales Spiel bauen # Normales Spiel bauen
# -------------------------- # --------------------------
@@ -23,13 +22,13 @@ main.o: main.c
$(CC) -c $(CFLAGS) main.c $(CC) -c $(CFLAGS) main.c
input.o: input.c input.o: input.c
$(CC) -c $(CFLAGS)input.c $(CC) -c $(CFLAGS) input.c
game.o: game.c game.o: game.c
$(CC) -c $(CFLAGS) game.c $(CC) -c $(CFLAGS) game.c
graphicalGame.o: graphicalGame.c graphicalGame.o: graphicalGame.c
$(CC) -I$(raylib_folder) -c $(CFLAGS) graphicalGame.c $(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
# -------------------------- # --------------------------
# Unit Tests # Unit Tests
+30
View File
@@ -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 ---------- // ---------- Test Setup und TearDown Funktionen ----------
// Hier Setup- und TearDown-Funktionen definieren, // Hier Setup- und TearDown-Funktionen definieren,
@@ -135,6 +164,7 @@ int main(void) {
RUN_TEST(test_readWords_empty_file); RUN_TEST(test_readWords_empty_file);
RUN_TEST(test_createWordSalad_all_fit); RUN_TEST(test_createWordSalad_all_fit);
RUN_TEST(test_createWordSalad_too_small); RUN_TEST(test_createWordSalad_too_small);
RUN_TEST(test_createWordSalad_allWordsPlaced);
int result = UNITY_END(); // Test-Ergebnisse int result = UNITY_END(); // Test-Ergebnisse
print_test_result(result); print_test_result(result);