diff --git a/test_numbers.c b/test_numbers.c index e69de29..28a3ebe 100644 --- a/test_numbers.c +++ b/test_numbers.c @@ -0,0 +1,53 @@ +#include +#include +#include "numbers.h" + +int main() { + printf("===== TEST NUMBERS =====\n"); + + unsigned int len = 20; + unsigned int *arr = createNumbers(len); + + if (arr == NULL) { + printf("FAIL: createNumbers returned NULL\n"); + return 1; + } + + // Check length: should contain len numbers + printf("PASS: createNumbers != NULL\n"); + + // Count duplicates — exactly one number must appear twice + int countDuplicate = 0; + + for (unsigned int i = 0; i < len; i++) { + for (unsigned int j = i + 1; j < len; j++) { + if (arr[i] == arr[j]) { + countDuplicate++; + } + } + } + + if (countDuplicate != 1) { + printf("FAIL: Array must contain exactly one duplicate, found %d\n", countDuplicate); + free(arr); + return 1; + } + printf("PASS: exactly one duplicate\n"); + + unsigned int found = getDuplicate(arr, len); + printf("Duplicate found by getDuplicate(): %u\n", found); + + if (found == 0) { + printf("FAIL: getDuplicate returned 0\n"); + free(arr); + return 1; + } + + printf("PASS: getDuplicate\n"); + + free(arr); + printf("PASS: free array\n"); + + printf("ALL NUMBERS TESTS PASSED\n"); + return 0; +} diff --git a/test_numbers.exe b/test_numbers.exe new file mode 100644 index 0000000..2782979 Binary files /dev/null and b/test_numbers.exe differ diff --git a/test_stack.c b/test_stack.c index e69de29..8ea2c5a 100644 --- a/test_stack.c +++ b/test_stack.c @@ -0,0 +1,36 @@ +#include +#include +#include "stack.h" + +int main() { + printf("===== TEST STACK =====\n"); + + StackNode *s = NULL; + + // Test push + int a = 10, b = 20, c = 30; + s = push(s, &a); + s = push(s, &b); + s = push(s, &c); + + if (*(int*)top(s) != 30) { + printf("FAIL: top() should return 30\n"); + return 1; + } + printf("PASS: push + top\n"); + + // Test pop + s = pop(s); + if (*(int*)top(s) != 20) { + printf("FAIL: pop() should remove 30\n"); + return 1; + } + printf("PASS: pop\n"); + + // Clear + clearStack(s); + printf("PASS: clearStack (no crash)\n"); + + printf("ALL STACK TESTS PASSED\n"); + return 0; +} diff --git a/test_stack.exe b/test_stack.exe new file mode 100644 index 0000000..88520a5 Binary files /dev/null and b/test_stack.exe differ