33 return *((
const int *)
ob);
39 return *((
const int *)
a) - *((
const int *)
b);
56 FAIL_UNLESS(
result == 0,
"Minheap should have allowed 1 element, but allowed 0.");
65 FAIL_UNLESS(
result == NULL,
"Empty heap should not return a non-null value on remove.");
66 int vals[3] = {1, 2, 3};
69 FAIL_UNLESS(
result == &vals[0],
"Heap should have returned the only value it was given (%d)", vals[0]);
79 int vals[30] = {4, 6, 23, 7, 343, 12, 1, 1, 33, 76, 4, 34, 8, 7, 90, 123, 2, 3, 55, 65, 4, 6, 77, 65, 5, 7, 6, 5, 4, 1};
80 int expected[30], actual[30];
82 memcpy(expected, vals,
sizeof(
int)*30);
87 for (
int i = 0; i < 30; ++i) {
89 FAIL_UNLESS(
result == 0,
"Failed to insert to the heap for index %d (%d).", i, vals[i]);
92 for (
int i = 0; i < 30; ++i) {
94 FAIL_UNLESS(
result != NULL,
"Failed to remove from the heap after %d elements.", i);
96 FAIL_UNLESS(expected[i] == actual[i],
"Heap did not gather data correctly. (%d != %d)", expected[i], actual[i]);
108 const Pos *p =
static_cast<const Pos *
>(
ob);
111 return diag * 3 + rem * 2;
120 Pos vals[400], expected[400], actual[400];
123 for (
int i = 0; i < 400; ++i) {
124 vals[i].
x = rand() & 16535;
125 vals[i].
y = rand() & 16535;
128 memcpy(expected, vals, 400 *
sizeof(
Pos));
132 for (
int i = 0; i < 400; ++i) {
137 for (
int i = 0; i < 400; ++i) {
139 FAIL_UNLESS(
res != NULL,
"Minheap emptied before it should have: %d items should be left.", 400-i);
143 "Minheap retrieved wrong value. Expected (%d, %d): %d, got (%d, %d): %d", expected[i].
x, expected[i].
y,
159 vals[i] = rand() & 32767;
162 memcpy(expected, vals,
HEAP_SIZE *
sizeof(
int));
174 FAIL_UNLESS(ref != NULL,
"Minheap emptied before it should have: %d items should be left.",
HEAP_SIZE - i);
175 FAIL_UNLESS(*ref == expected[i],
"Minheap retrieved wrong value. Expected %d, got %d.", expected[i], *ref);
181 Suite *s = suite_create(
"minheap");
182 TCase *tc_core = tcase_create(
"Core");
183 tcase_set_timeout(tc_core, 60);
188 suite_add_tcase(s, tc_core);
189 tcase_add_test(tc_core, test_minheap_allocate);
190 tcase_add_test(tc_core, test_minheap_overfill);
191 tcase_add_test(tc_core, test_minheap_empty_remove);
192 tcase_add_test(tc_core, test_minheap_insert_remove);
193 tcase_add_test(tc_core, test_minheap_with_struct);
194 tcase_add_test(tc_core, test_minheap_static_alloc);
202 SRunner *sr = srunner_create(s);
207 srunner_set_xml(sr, LOGDIR
"/unit/common/minheap.xml");
208 srunner_set_log(sr, LOGDIR
"/unit/common/minheap.out");
209 srunner_run_all(sr, CK_ENV);
210 nf = srunner_ntests_failed(sr);
212 return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;