| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gate/tests.h" | ||
| 2 | #include "test_arrays.h" | ||
| 3 | #include "gate/arrays.h" | ||
| 4 | #include "gate/comparers.h" | ||
| 5 | |||
| 6 | 1 | GATE_TEST_FUNCTION(test_arraylists) | |
| 7 | { | ||
| 8 | static int const i1 = 1; | ||
| 9 | static int const i2 = 2; | ||
| 10 | static int const i3 = 3; | ||
| 11 | 1 | gate_arraylist_t al = NULL; | |
| 12 | 1 | gate_arraylist_t al2 = NULL; | |
| 13 | gate_result_t result; | ||
| 14 | 1 | void* ptr_item = NULL; | |
| 15 | |||
| 16 | |||
| 17 | 1 | GATE_TEST_UNIT_BEGIN(test_arraylists); | |
| 18 | |||
| 19 | 1 | al = gate_arraylist_create(sizeof(int), NULL, 0, NULL, NULL); | |
| 20 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(al != NULL); |
| 21 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 0); |
| 22 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_itemsize(al), sizeof(int)); |
| 23 | |||
| 24 | 1 | ptr_item = gate_arraylist_add(al, &i1); | |
| 25 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 26 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i1); |
| 27 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 1); |
| 28 | |||
| 29 | 1 | ptr_item = gate_arraylist_add(al, &i2); | |
| 30 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 31 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i2); |
| 32 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 2); |
| 33 | |||
| 34 | 1 | ptr_item = gate_arraylist_add(al, &i3); | |
| 35 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 36 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i3); |
| 37 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 3); |
| 38 | |||
| 39 | 1 | ptr_item = gate_arraylist_get(al, 0); | |
| 40 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 41 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i1); |
| 42 | |||
| 43 | 1 | ptr_item = gate_arraylist_get(al, 1); | |
| 44 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 45 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i2); |
| 46 | |||
| 47 | 1 | ptr_item = gate_arraylist_get(al, 2); | |
| 48 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 49 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i3); |
| 50 | |||
| 51 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_arraylist_remove(al, 1, 1)); |
| 52 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 2); |
| 53 | |||
| 54 | 1 | ptr_item = gate_arraylist_get(al, 0); | |
| 55 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 56 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i1); |
| 57 | |||
| 58 | 1 | ptr_item = gate_arraylist_get(al, 1); | |
| 59 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_item != NULL); |
| 60 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i3); |
| 61 | |||
| 62 | 1 | result = gate_arraylist_copy_constructor(&al2, &al); | |
| 63 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
| 64 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), gate_arraylist_length(al2)); |
| 65 | 1 | gate_arraylist_destructor(&al2); | |
| 66 | |||
| 67 | 1 | gate_arraylist_release(al); | |
| 68 | |||
| 69 | 1 | GATE_TEST_UNIT_END; | |
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | 8 | static gate_bool_t find_odd(void const* item, void* param) | |
| 74 | { | ||
| 75 | 8 | gate_int16_t const* ptr = (gate_int16_t const*)item; | |
| 76 | GATE_UNUSED_ARG(param); | ||
| 77 | |||
| 78 | 8 | return (*ptr % 2) == 1; | |
| 79 | } | ||
| 80 | |||
| 81 | 1 | GATE_TEST_FUNCTION(test_arrayutils) | |
| 82 | { | ||
| 83 | 1 | gate_int16_t iarr[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; | |
| 84 | 1 | gate_size_t const iarr_sz = sizeof(iarr) / sizeof(iarr[0]); | |
| 85 | 1 | gate_array_t arr = GATE_INIT_EMPTY; | |
| 86 | 1 | gate_array_t* ptr_arr = NULL; | |
| 87 | 1 | gate_array_t arrcopy = GATE_INIT_EMPTY; | |
| 88 | gate_result_t result; | ||
| 89 | gate_size_t new_size; | ||
| 90 | |||
| 91 | 1 | GATE_TEST_UNIT_BEGIN(test_arrayutils); | |
| 92 | |||
| 93 | 1 | ptr_arr = gate_array_create_static(&arr, iarr, sizeof(iarr[0]), iarr_sz); | |
| 94 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_arr != NULL); |
| 95 | |||
| 96 | 1 | result = gate_array_copy_constructor(&arrcopy, ptr_arr); | |
| 97 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
| 98 | |||
| 99 | 1 | gate_array_sort(iarr, sizeof(iarr[0]), iarr_sz, &gate_compare_int16, NULL, NULL); | |
| 100 | 1 | gate_array_sort_descending(iarr, sizeof(iarr[0]), iarr_sz, &gate_compare_int16, NULL, NULL); | |
| 101 | |||
| 102 | 1 | gate_array_destructor(&arrcopy); | |
| 103 | |||
| 104 | 1 | gate_array_release(&arr); | |
| 105 | |||
| 106 | 1 | new_size = gate_array_remove_if(iarr, sizeof(iarr[0]), iarr_sz, &find_odd, NULL, NULL, NULL); | |
| 107 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(new_size, iarr_sz / 2); |
| 108 | |||
| 109 | 1 | GATE_TEST_UNIT_END; | |
| 110 | } | ||
| 111 | |||
| 112 | 1 | GATE_TEST_FUNCTION(test_arrays) | |
| 113 | { | ||
| 114 | 1 | gate_bool_t result = true; | |
| 115 | |||
| 116 | 1 | result |= test_arraylists(); | |
| 117 | 1 | result |= test_arrayutils(); | |
| 118 | |||
| 119 | 1 | return result; | |
| 120 | } | ||
| 121 |