aboutsummaryrefslogtreecommitdiff
path: root/tests/ds
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ds')
-rw-r--r--tests/ds/array_tests.c37
-rw-r--r--tests/ds/hashmap_tests.c21
2 files changed, 45 insertions, 13 deletions
diff --git a/tests/ds/array_tests.c b/tests/ds/array_tests.c
index c5d7c4d..975443c 100644
--- a/tests/ds/array_tests.c
+++ b/tests/ds/array_tests.c
@@ -16,10 +16,16 @@ TEST(cap_test) {
test_assert(arr_cap(arr) == 2 * MOS_ARR_INIT_CAP, "capacity didn't increase 2 times");
size_t new_cap = arr_set_cap(arr, 3 * MOS_ARR_INIT_CAP);
- test_assert(new_cap == arr_cap(arr) && new_cap == 3 * MOS_ARR_INIT_CAP, "set cap didn't set correct capacity (cap >= len)");
+ test_assert(
+ new_cap == arr_cap(arr) && new_cap == 3 * MOS_ARR_INIT_CAP,
+ "set cap didn't set correct capacity (cap >= len)"
+ );
new_cap = arr_set_cap(arr, 0);
- test_assert(new_cap == arr_cap(arr) && new_cap == MOS_ARR_INIT_CAP + 1, "set cap didn't set correct capacity (cap < len)");
+ test_assert(
+ new_cap == arr_cap(arr) && new_cap == MOS_ARR_INIT_CAP + 1,
+ "set cap didn't set correct capacity (cap < len)"
+ );
arr_free(arr);
}
@@ -95,10 +101,14 @@ TEST(getting_items) {
test_assert(arr_last(arr) == NULL, "last of empty array isn't null");
arr_append(arr, (struct test){0});
- test_assert(arr_first(arr) == arr_last(arr), "first and last are different for array of length 1");
+ test_assert(
+ arr_first(arr) == arr_last(arr), "first and last are different for array of length 1"
+ );
arr_append(arr, (struct test){1, 1});
- test_assert(arr_first(arr) != arr_last(arr), "first and last are the same for array of length >1");
+ test_assert(
+ arr_first(arr) != arr_last(arr), "first and last are the same for array of length >1"
+ );
struct test *next_first = arr_next(arr, NULL);
struct test *next_last = arr_next(arr, next_first);
@@ -108,15 +118,24 @@ TEST(getting_items) {
struct test *prev_null = arr_prev(arr, prev_first);
test_assert(next_first && next_last, "next gave NULL when it shouldn't have");
test_assert(prev_first && prev_last, "prev gave NULL when it shouldn't have");
- test_assert(next_first == prev_first && next_last == prev_last, "next and prev gave different values for the same element");
+ test_assert(
+ next_first == prev_first && next_last == prev_last,
+ "next and prev gave different values for the same element"
+ );
test_assert(!next_null, "next didn't give NULL after running out of items");
test_assert(!prev_null, "prev didn't give NULL after running out of items");
- test_assert(arr_get(arr, -1) == NULL && arr_get(arr, 2) == NULL, "arr_get didn't give NULL when out of bounds");
+ test_assert(
+ arr_get(arr, -1) == NULL && arr_get(arr, 2) == NULL,
+ "arr_get didn't give NULL when out of bounds"
+ );
struct test i0 = *arr_get(arr, 0);
struct test i1 = *arr_get(arr, 1);
- test_assert(!memcmp(&i0, &arr[0], sizeof(struct test)) && !memcmp(&i1, &arr[1], sizeof(struct test)), "arr_get(arr, i) gives different result than arr[i]");
+ test_assert(
+ !memcmp(&i0, &arr[0], sizeof(struct test)) && !memcmp(&i1, &arr[1], sizeof(struct test)),
+ "arr_get(arr, i) gives different result than arr[i]"
+ );
arr_free(arr);
}
@@ -176,7 +195,9 @@ TEST(arr_concat_test) {
test_assert(index == 2, "arr_concat returned wrong index");
unsigned long expected[] = {4, 5, 1, 2, 3, 4, 5};
test_assert(arr_len(arr2) == 7, "arr_concat produced array of wrong length");
- test_assert(!memcmp(arr2, expected, 7 * sizeof(unsigned long)), "arr_concat produced wrong array");
+ test_assert(
+ !memcmp(arr2, expected, 7 * sizeof(unsigned long)), "arr_concat produced wrong array"
+ );
arr_free(arr1);
arr_free(arr2);
diff --git a/tests/ds/hashmap_tests.c b/tests/ds/hashmap_tests.c
index 4c615a7..268bc29 100644
--- a/tests/ds/hashmap_tests.c
+++ b/tests/ds/hashmap_tests.c
@@ -45,13 +45,19 @@ TEST(put_e_get_e) {
hm_put_e(hm, (E){0.0f, 69});
hm_put_e(hm, (E){1.0f, 420});
E e = {0.0f, 69};
- test_assert(memcmp(&e, hm_get_e(hm, 0.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e");
+ test_assert(
+ memcmp(&e, hm_get_e(hm, 0.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e"
+ );
e = (E){1.0f, 420};
- test_assert(memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e");
+ test_assert(
+ memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_get_e got entry not from hm_put_e"
+ );
e = (E){1.0f, 2137};
hm_put_e(hm, e);
- test_assert(memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_put_e didn't update entry properly");
+ test_assert(
+ memcmp(&e, hm_get_e(hm, 1.0f), sizeof(E)) == 0, "hm_put_e didn't update entry properly"
+ );
hm_free(hm);
}
@@ -137,7 +143,9 @@ TEST(looping) {
E items[] = {{1, 10}, {2, 20}, {3, 30}};
arr_append_n(allowed, items, 3);
- test_assert(memcmp(hm_first(hm), hm_next(hm, NULL), sizeof(E)) == 0, "hm_next(hm, NULL) != hm_first(hm)");
+ test_assert(
+ memcmp(hm_first(hm), hm_next(hm, NULL), sizeof(E)) == 0, "hm_next(hm, NULL) != hm_first(hm)"
+ );
E *e = NULL;
while ((e = hm_next(hm, e))) {
int flag = 0;
@@ -150,7 +158,10 @@ TEST(looping) {
}
test_assert(flag, "hm_next produced an entry that wasn't put in the hashmap");
}
- test_assert(arr_len(allowed) == 0, "hm_next didn't produce every entry from hashmap when it looped over it");
+ test_assert(
+ arr_len(allowed) == 0,
+ "hm_next didn't produce every entry from hashmap when it looped over it"
+ );
arr_free(allowed);
hm_free(hm);