summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tree_debug.h7
-rw-r--r--test/sorted_array_test.c28
2 files changed, 19 insertions, 16 deletions
diff --git a/src/tree_debug.h b/src/tree_debug.h
index 74f4e0e..e903265 100644
--- a/src/tree_debug.h
+++ b/src/tree_debug.h
@@ -90,7 +90,8 @@ verify_balance(ZixTreeNode* n)
const intptr_t left_height = (intptr_t)height(n->left);
const intptr_t right_height = (intptr_t)height(n->right);
if (n->balance != right_height - left_height) {
- fprintf(stderr, "Bad balance at %ld: h_r (%zu) - l_h (%zu) != %d\n",
+ fprintf(stderr, "Bad balance at %ld: h_r (%" PRIdPTR ")"
+ "- l_h (%" PRIdPTR ") != %d\n",
(intptr_t)n->data, right_height, left_height, n->balance);
assert(false);
return false;
@@ -118,7 +119,7 @@ verify(ZixTree* t, ZixTreeNode* n)
if (n->left) {
if (t->cmp(n->left->data, n->data, t->cmp_data) > 0) {
- fprintf(stderr, "Bad order: %zu with left child\n",
+ fprintf(stderr, "Bad order: %" PRIdPTR " with left child\n",
(intptr_t)n->data);
fprintf(stderr, "%p ? %p\n", (void*)n, (void*)n->left);
fprintf(stderr, "%" PRIdPTR " ? %" PRIdPTR "\n", (intptr_t)n->data,
@@ -132,7 +133,7 @@ verify(ZixTree* t, ZixTreeNode* n)
if (n->right) {
if (t->cmp(n->right->data, n->data, t->cmp_data) < 0) {
- fprintf(stderr, "Bad order: %zu with right child\n",
+ fprintf(stderr, "Bad order: %" PRIdPTR " with right child\n",
(intptr_t)n->data);
return false;
}
diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c
index 13f7f32..d33151a 100644
--- a/test/sorted_array_test.c
+++ b/test/sorted_array_test.c
@@ -39,7 +39,7 @@ int_cmp(const void* a, const void* b, void* user_data)
}
static int
-ith_elem(int test_num, size_t n_elems, int i)
+ith_elem(int test_num, unsigned n_elems, int i)
{
switch (test_num % 3) {
case 0:
@@ -59,7 +59,7 @@ test_fail()
}
static int
-stress(int test_num, size_t n_elems)
+stress(int test_num, unsigned n_elems)
{
intptr_t r;
ZixSortedArrayIter ti;
@@ -69,7 +69,7 @@ stress(int test_num, size_t n_elems)
srand(seed);
// Insert n_elems elements
- for (size_t i = 0; i < n_elems; ++i) {
+ for (unsigned i = 0; i < n_elems; ++i) {
r = ith_elem(test_num, n_elems, i);
int status = zix_sorted_array_insert(t, &r, &ti);
if (status) {
@@ -77,7 +77,8 @@ stress(int test_num, size_t n_elems)
return test_fail();
}
if (*(intptr_t*)zix_sorted_array_get_data(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR ", expected %zu)\n",
+ fprintf(stderr, "Data corrupt (saw %" PRIdPTR
+ ", expected %" PRIdPTR ")\n",
*(intptr_t*)zix_sorted_array_get_data(ti), r);
return test_fail();
}
@@ -86,14 +87,15 @@ stress(int test_num, size_t n_elems)
srand(seed);
// Search for all elements
- for (size_t i = 0; i < n_elems; ++i) {
+ for (unsigned i = 0; i < n_elems; ++i) {
r = ith_elem(test_num, n_elems, i);
if (zix_sorted_array_find(t, &r, &ti)) {
fprintf(stderr, "Find failed\n");
return test_fail();
}
if (*(intptr_t*)zix_sorted_array_get_data(ti) != r) {
- fprintf(stderr, "Data corrupt (saw %" PRIdPTR ", expected %zu)\n",
+ fprintf(stderr, "Data corrupt (saw %" PRIdPTR
+ ", expected %" PRIdPTR ")\n",
*(intptr_t*)zix_sorted_array_get_data(ti), r);
return test_fail();
}
@@ -102,7 +104,7 @@ stress(int test_num, size_t n_elems)
srand(seed);
// Iterate over all elements
- size_t i = 0;
+ unsigned i = 0;
intptr_t last = -1;
for (ZixSortedArrayIter iter = zix_sorted_array_begin(t);
!zix_sorted_array_iter_is_end(t, iter);
@@ -110,7 +112,7 @@ stress(int test_num, size_t n_elems)
r = ith_elem(test_num, n_elems, i);
const intptr_t iter_data = *(intptr_t*)zix_sorted_array_get_data(iter);
if (iter_data < last) {
- fprintf(stderr, "Iter corrupt (%" PRIdPTR " < %zu)\n",
+ fprintf(stderr, "Iter corrupt (%" PRIdPTR " < %" PRIdPTR ")\n",
iter_data, last);
return test_fail();
}
@@ -120,7 +122,7 @@ stress(int test_num, size_t n_elems)
srand(seed);
// Delete all elements
- for (size_t i = 0; i < n_elems; i++) {
+ for (unsigned i = 0; i < n_elems; i++) {
r = ith_elem(test_num, n_elems, i);
ZixSortedArrayIter item;
if (zix_sorted_array_find(t, &r, &item) != ZIX_STATUS_SUCCESS) {
@@ -145,8 +147,8 @@ stress(int test_num, size_t n_elems)
int
main(int argc, char** argv)
{
- const size_t n_tests = 3;
- size_t n_elems = 0;
+ const unsigned n_tests = 3;
+ unsigned n_elems = 0;
struct timeval time;
gettimeofday(&time, NULL);
@@ -167,10 +169,10 @@ main(int argc, char** argv)
return 1;
}
- printf("Running %zu tests with %zu elements (seed %d)",
+ printf("Running %u tests with %u elements (seed %d)",
n_tests, n_elems, seed);
- for (size_t i = 0; i < n_tests; ++i) {
+ for (unsigned i = 0; i < n_tests; ++i) {
printf(".");
fflush(stdout);
if (stress(i, n_elems)) {