From d25dfd669bde41d2cb6cafc826f84d730f2c4d8c Mon Sep 17 00:00:00 2001 From: manusmac Date: Mon, 12 Jan 2026 15:07:50 +0100 Subject: [PATCH] test_numbers implementiert und in makefile eingebunden --- highscores.txt | 1 + makefile | 5 +++-- test_numbers.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test_numbers.c diff --git a/highscores.txt b/highscores.txt index 43e141f..4be79c5 100644 --- a/highscores.txt +++ b/highscores.txt @@ -1,4 +1,5 @@ manu;9959 manu;9949 player2;9925 +manu;4983 player1;3999 diff --git a/makefile b/makefile index ee50194..a412fa6 100644 --- a/makefile +++ b/makefile @@ -37,13 +37,14 @@ $(program_obj_filesobj_files): %.o: %.c # -------------------------- unitTests: $(CC) $(FLAGS) $^ -o test_stack test_stack.c stack.c -Wall && ./test_stack + $(CC) $(FLAGS) $^ -o test_numbers test_numbers.c numbers.c bintree.c stack.c -Wall && ./test_numbers # -------------------------- # Clean # -------------------------- clean: ifeq ($(OS),Windows_NT) - del /f *.o doble test_stack + del /f *.o doble test_stack test_numbers else - rm -f *.o doble test_stack + rm -f *.o doble test_stack test_numbers endif \ No newline at end of file diff --git a/test_numbers.c b/test_numbers.c new file mode 100644 index 0000000..a6f3b17 --- /dev/null +++ b/test_numbers.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include "stack.h" +#include "numbers.h" + +int main() +{ + printf("=== Test createNumbers & getDuplicate ===\n\n"); + + unsigned int len = 10; + unsigned int *numbers = createNumbers(len); + + if (numbers == NULL) + { + printf("Fehler: createNumbers() gab NULL zurück\n"); + return 1; + } + + printf("Generierte Zahlen: "); + for (unsigned int i = 0; i < len; i++) + { + printf("%u ", numbers[i]); + } + printf("\n\n"); + + unsigned int duplicate = getDuplicate(numbers, len); + + if (duplicate == 0) + { + printf("Fehler: Kein Duplikat gefunden\n"); + } + else + { + printf("Gefundenes Duplikat: %u\n", duplicate); + + // Prüfen, ob es wirklich zweimal vorkommt + int count = 0; + for (unsigned int i = 0; i < len; i++) + { + if (numbers[i] == duplicate) + { + count++; + } + } + printf("Anzahl Vorkommen: %d\n", count); + + if (count == 2) + { + printf("\n[PASSED] Test erfolgreich!\n"); + } + else + { + printf("\n[FAILED] Duplikat kommt %d mal vor (erwartet: 2)\n", count); + } + } + + free(numbers); + return 0; +} \ No newline at end of file