Compare commits
1 Commits
96e1a8e0d6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
baa683d970
|
22
test/array.c
22
test/array.c
@@ -1,11 +1,8 @@
|
||||
#define L_ARRAY_IMPLEMENTATION
|
||||
#include "../include/larray.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,29 +1,25 @@
|
||||
#define L_STRING_IMPLEMENTATION
|
||||
#include "../include/lstring.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
}
|
||||
10
test/test.c
10
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;
|
||||
}
|
||||
Reference in New Issue
Block a user