Make the heapsort test comparison work..

This commit is contained in:
Nils O. Selåsdal
2013-12-03 17:29:00 +01:00
parent 4caf2573fb
commit 2b022aeddc
+18 -5
View File
@@ -37,6 +37,19 @@ void print_stuff(const struct Stuff *s, size_t len)
}
}
static int cmp_stuff_array(const struct Stuff *a, const struct Stuff *b, size_t len)
{
size_t i;
for (i = 0; i < len; i++) {
if (strcmp(a[i].text, b[i].text) != 0)
return -1;
if (a[i].order != b[i].order)
return -1;
}
return 0;
}
START_TEST (test_heapsort_odd)
struct Stuff unordered[] = {
{"2", 2},
@@ -56,8 +69,8 @@ START_TEST (test_heapsort_odd)
uc_heapsort(unordered, ARRAY_SIZE(unordered), sizeof(struct Stuff),
cmp_stuff, swap_stuff, NULL);
//print_stuff(unordered, ARRAY_SIZE(unordered));
fail_if(memcmp(unordered, ordered, sizeof unordered) != 0);
print_stuff(unordered, ARRAY_SIZE(unordered));
fail_if(cmp_stuff_array(unordered, ordered, ARRAY_SIZE(unordered)) != 0);
END_TEST
START_TEST (test_heapsort_even)
@@ -81,7 +94,7 @@ START_TEST (test_heapsort_even)
uc_heapsort(unordered, ARRAY_SIZE(unordered), sizeof(struct Stuff),
cmp_stuff, swap_stuff, NULL);
fail_if(memcmp(unordered, ordered, sizeof unordered) != 0);
fail_if(cmp_stuff_array(unordered, ordered, ARRAY_SIZE(unordered)) != 0);
END_TEST
START_TEST (test_heapsort_zero)
@@ -105,11 +118,11 @@ START_TEST (test_heapsort_zero)
uc_heapsort(unordered, 0, sizeof(struct Stuff),
cmp_stuff, swap_stuff, NULL);
fail_if(memcmp(unordered, same, sizeof unordered) != 0);
fail_if(cmp_stuff_array(unordered, same, ARRAY_SIZE(unordered)) != 0);
uc_heapsort(unordered, ARRAY_SIZE(unordered), 0,
cmp_stuff, swap_stuff, NULL);
fail_if(memcmp(unordered, same, sizeof unordered) != 0);
fail_if(cmp_stuff_array(unordered, same, ARRAY_SIZE(unordered)) != 0);
END_TEST
Suite *heapsort_suite(void)