Dateien nach "Start_Windows" hochladen
This commit is contained in:
parent
383abf157b
commit
f398d5b87a
45
Start_Windows/makefile
Normal file
45
Start_Windows/makefile
Normal file
@ -0,0 +1,45 @@
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
|
||||
BINARIES = ./windows
|
||||
|
||||
raylibfolder = ./raylib
|
||||
unityfolder = ./unity
|
||||
|
||||
# --------------------------
|
||||
# initiales Spiel bauen
|
||||
# --------------------------
|
||||
wordsalad_initial:
|
||||
$(CC) -o wordsalad_initial $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
# --------------------------
|
||||
# Normales Spiel bauen
|
||||
# --------------------------
|
||||
all: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
main.o: main.c
|
||||
$(CC) -c $(CFLAGS) main.c
|
||||
|
||||
input.o: input.c
|
||||
$(CC) -c $(CFLAGS) input.c
|
||||
|
||||
game.o: game.c
|
||||
$(CC) -c $(CFLAGS) game.c
|
||||
|
||||
graphicalGame.o: graphicalGame.c
|
||||
$(CC) -I$(raylibfolder) -c $(CFLAGS) graphicalGame.c
|
||||
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
TEST_BIN = runTests
|
||||
|
||||
test: input.o game.o unit_tests.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o $(TEST_BIN) input.o game.o unit_tests.c $(BINARIES)/libunity.a
|
||||
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
clean:
|
||||
del /f *.o *.exe
|
||||
173
Start_Windows/unit_tests.c
Normal file
173
Start_Windows/unit_tests.c
Normal file
@ -0,0 +1,173 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "unity.h"
|
||||
|
||||
#include "input.h"
|
||||
#include "game.h"
|
||||
|
||||
// ANSI Escape Codes für Farben
|
||||
// Hinweis: damit das in CLion mit der integrierten Konsole/Output funktioniert, muss man auf die Run-Config gehen und
|
||||
// das Häkchen bei 'emulate terminal in the output console' setzen
|
||||
// (s. auch: https://stackoverflow.com/questions/32742850/how-to-show-colored-console-output-in-clion)
|
||||
#define RESET "\033[0m"
|
||||
#define GREEN "\033[32m"
|
||||
#define RED "\033[31m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define CYAN "\033[36m"
|
||||
#define BOLD "\033[1m"
|
||||
|
||||
// Eine Funktion, um die Test-Ergebnisse zu färben
|
||||
void print_test_result(int result) {
|
||||
if (result == 0) {
|
||||
// Test war erfolgreich
|
||||
printf(GREEN "OK\n" RESET);
|
||||
} else {
|
||||
// Test ist fehlgeschlagen
|
||||
printf(RED "FAILED\n" RESET);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Tests für input.c ----------
|
||||
void test_readWords_simple(void) {
|
||||
FILE *f = fopen("testwords_simple.txt", "r");
|
||||
|
||||
char words[10][MAX_WORD_LEN];
|
||||
int count = readWords(f, words, 10);
|
||||
fclose(f);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(3, count);
|
||||
TEST_ASSERT_EQUAL_STRING("APFEL", words[0]);
|
||||
TEST_ASSERT_EQUAL_STRING("BANANE", words[1]);
|
||||
TEST_ASSERT_EQUAL_STRING("KIWI", words[2]);
|
||||
}
|
||||
|
||||
void test_readWords_with_delimiters(void) {
|
||||
FILE *f = fopen("testwords_delims.txt", "r");
|
||||
|
||||
char words[10][MAX_WORD_LEN];
|
||||
int count = readWords(f, words, 10);
|
||||
fclose(f);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(3, count);
|
||||
TEST_ASSERT_EQUAL_STRING("HUND", words[0]);
|
||||
TEST_ASSERT_EQUAL_STRING("KATZE", words[1]);
|
||||
TEST_ASSERT_EQUAL_STRING("MAUS", words[2]);
|
||||
}
|
||||
|
||||
void test_readWords_empty_file(void) {
|
||||
FILE *f = fopen("testwords_empty.txt", "r");
|
||||
|
||||
char words[10][MAX_WORD_LEN];
|
||||
int count = readWords(f, words, 10);
|
||||
fclose(f);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, count);
|
||||
}
|
||||
|
||||
// ---------- Tests für game.c ----------
|
||||
void test_createWordSalad_all_fit(void) {
|
||||
char words[3][MAX_WORD_LEN] = {"CAT", "DOG", "MOUSE"};
|
||||
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||
|
||||
int placed = createWordSalad(salad, 20, words, 3);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(3, placed);
|
||||
|
||||
// Sicherstellen, dass alle Felder gefüllt sind
|
||||
for (int i = 0; i < 20; i++) {
|
||||
for (int j = 0; j < 20; j++) {
|
||||
TEST_ASSERT_GREATER_OR_EQUAL('A', salad[i][j]);
|
||||
TEST_ASSERT_LESS_OR_EQUAL('Z', salad[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_createWordSalad_too_small(void) {
|
||||
char words[2][MAX_WORD_LEN] = {"ELEPHANT", "GIRAFFE"};
|
||||
char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN];
|
||||
|
||||
int placed = createWordSalad(salad, 5, words, 2);
|
||||
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(0, placed);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(2, placed);
|
||||
|
||||
// Feld muss vollständig gefüllt sein
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 5; j++) {
|
||||
TEST_ASSERT_GREATER_OR_EQUAL('A', salad[i][j]);
|
||||
TEST_ASSERT_LESS_OR_EQUAL('Z', salad[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
void setUp(void) {
|
||||
FILE *f = fopen("testwords_delims.txt", "w");
|
||||
fprintf(f, "Hund,Katze; Maus\n");
|
||||
fclose(f);
|
||||
|
||||
f = fopen("testwords_simple.txt", "w");
|
||||
fprintf(f, "Apfel\nBanane\nKiwi");
|
||||
fclose(f);
|
||||
|
||||
f = fopen("testwords_empty.txt", "w");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
remove("testwords_delims.txt");
|
||||
remove("testwords_simple.txt");
|
||||
remove("testwords_empty.txt");
|
||||
}
|
||||
|
||||
// ---------- Test Runner ----------
|
||||
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_readWords_simple);
|
||||
RUN_TEST(test_readWords_with_delimiters);
|
||||
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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user