test_numbers implementiert und in makefile eingebunden
This commit is contained in:
parent
a3f8aedb26
commit
d25dfd669b
@ -1,4 +1,5 @@
|
||||
manu;9959
|
||||
manu;9949
|
||||
player2;9925
|
||||
manu;4983
|
||||
player1;3999
|
||||
|
||||
5
makefile
5
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
|
||||
60
test_numbers.c
Normal file
60
test_numbers.c
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user