From baa683d9706e9ccf44fcd4f1d20916de2a9d59fd Mon Sep 17 00:00:00 2001 From: lucielle Date: Sun, 12 Jul 2026 18:09:46 -0500 Subject: [PATCH] use assert instead of ambiuous return code --- test/array.c | 22 +++++++++------------- test/string.c | 14 +++++--------- test/test.c | 10 ++++------ 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/test/array.c b/test/array.c index 5346751..2104d11 100644 --- a/test/array.c +++ b/test/array.c @@ -1,11 +1,8 @@ #define L_ARRAY_IMPLEMENTATION #include "../include/larray.h" -#include +#include int test_l_array() { - int RETURN_CODE = 0; - printf("test_l_array() : "); - LArray* array = l_array_create(); int number_1 = 5; @@ -14,19 +11,18 @@ int test_l_array() { l_array_append(array, &number_2); l_array_append(array, &number_1); - if (*(int*)array->items[0] != 15) RETURN_CODE++; - if (*(int*)array->items[1] != 5) RETURN_CODE++; - if (array->count != 2) RETURN_CODE++; - if (array->capacity != 8) RETURN_CODE++; + assert(*(int*)array->items[0] == 15); + assert(*(int*)array->items[1] == 5); + assert(array->count == 2); + assert(array->capacity == 8); l_array_swap(array, 0, 1); - if (*(int*)array->items[0] != 5) RETURN_CODE++; - if (*(int*)array->items[1] != 15) RETURN_CODE++; + assert(*(int*)array->items[0] == 5); + assert(*(int*)array->items[1] == 15); l_array_clear(array); - if (array->items != NULL) RETURN_CODE++; + assert(array->items == NULL); - printf("%d\n", RETURN_CODE); l_array_delete(array); - return RETURN_CODE; + return 0; } \ No newline at end of file diff --git a/test/string.c b/test/string.c index 2b6beac..43d8103 100644 --- a/test/string.c +++ b/test/string.c @@ -1,29 +1,25 @@ #define L_STRING_IMPLEMENTATION #include "../include/lstring.h" -#include +#include int test_l_string() { - int RETURN_CODE = 0; - printf("test_l_string() : "); - int integer_0 = 25; int integer_1 = 15; LString* test_string_0 = l_string_new("I would like to purchase item id `%d`", integer_0); LString* test_string_1 = l_string_new(" for `%d` coins.", integer_1); - if (l_string_cmp(test_string_0, l_string_new("I would like to purchase item id `25`"))) RETURN_CODE++; - if (l_string_cmp(test_string_1, l_string_new(" for `15` coins."))) RETURN_CODE++; + assert(!l_string_cmp(test_string_0, l_string_new("I would like to purchase item id `25`"))); + assert(!l_string_cmp(test_string_1, l_string_new(" for `15` coins."))); LString* test_string_2 = l_string_new("I would like to purchase item id `25` for `15` coins."); LString* test_string_3 = l_string_concat(test_string_0, test_string_1); - if (l_string_cmp(test_string_2, test_string_3)) RETURN_CODE++; + assert(!l_string_cmp(test_string_2, test_string_3)); l_string_delete(test_string_0); l_string_delete(test_string_1); l_string_delete(test_string_2); l_string_delete(test_string_3); - printf("%d\n", RETURN_CODE); - return RETURN_CODE; + return 0; } \ No newline at end of file diff --git a/test/test.c b/test/test.c index 2fc4f10..10ffae8 100644 --- a/test/test.c +++ b/test/test.c @@ -13,12 +13,10 @@ int main(void) { printf("REPO: %s\n", L_TYPES_REPO); printf("VERSION: %s\n", L_TYPES_VERSION); printf("LICENSE: %s\n\n", L_TYPES_LICENSE); - - int RETURN_CODE = 0; - RETURN_CODE += test_l_array(); - RETURN_CODE += test_l_string(); + test_l_array(); + test_l_string(); - printf("\nError Total: %d\n", RETURN_CODE); - return RETURN_CODE; + printf("Test Completed Succefully.\n"); + return 0; } \ No newline at end of file