test_numbers implementiert und in makefile eingebunden

This commit is contained in:
Manuel Nitsche 2026-01-12 15:07:50 +01:00
parent a3f8aedb26
commit d25dfd669b
3 changed files with 64 additions and 2 deletions

View File

@ -1,4 +1,5 @@
manu;9959
manu;9949
player2;9925
manu;4983
player1;3999

View File

@ -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

60
test_numbers.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#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;
}