summaryrefslogtreecommitdiffstats
path: root/test/bitset_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-09-18 20:11:35 -0400
committerDavid Robillard <d@drobilla.net>2021-09-18 20:11:35 -0400
commit012116d975ff72da6f66486aa6547e2b5ce5e991 (patch)
tree2f068a5bb6927964feb72df91008616e41e9dedb /test/bitset_test.c
parent64285def12fcec4593a295e1281a28d0e22805a9 (diff)
downloadzix-012116d975ff72da6f66486aa6547e2b5ce5e991.tar.gz
zix-012116d975ff72da6f66486aa6547e2b5ce5e991.tar.bz2
zix-012116d975ff72da6f66486aa6547e2b5ce5e991.zip
Use assertions in Bitset test
Diffstat (limited to 'test/bitset_test.c')
-rw-r--r--test/bitset_test.c66
1 files changed, 14 insertions, 52 deletions
diff --git a/test/bitset_test.c b/test/bitset_test.c
index 261b1c3..ef61eeb 100644
--- a/test/bitset_test.c
+++ b/test/bitset_test.c
@@ -1,30 +1,17 @@
// Copyright 2014-2020 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "zix/attributes.h"
+#undef NDEBUG
+
#include "zix/bitset.h"
-#include <inttypes.h>
-#include <stdarg.h>
-#include <stdio.h>
+#include <assert.h>
#define N_BITS 256u
#define N_ELEMS (ZIX_BITSET_ELEMS(N_BITS))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-ZIX_LOG_FUNC(1, 2)
-static int
-test_fail(const char* fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
- fprintf(stderr, "error: ");
- vfprintf(stderr, fmt, args);
- va_end(args);
- return 1;
-}
-
int
main(void)
{
@@ -32,39 +19,28 @@ main(void)
ZixBitsetTally t[N_ELEMS];
zix_bitset_clear(b, t, N_BITS);
- if (zix_bitset_count_up_to(b, t, N_BITS) != 0) {
- return test_fail("Cleared bitset has non-zero count\n");
- }
+ assert(zix_bitset_count_up_to(b, t, N_BITS) == 0);
for (size_t i = 0; i < N_BITS; ++i) {
zix_bitset_set(b, t, i);
- const size_t count = zix_bitset_count_up_to(b, t, N_BITS);
- if (count != i + 1) {
- return test_fail("Count %" PRIuPTR " != %" PRIuPTR "\n", count, i + 1);
- }
+ assert(zix_bitset_get(b, i));
- if (!zix_bitset_get(b, i)) {
- return test_fail("Bit %" PRIuPTR " is not set\n", i);
- }
+ const size_t count = zix_bitset_count_up_to(b, t, N_BITS);
+ assert(count == i + 1);
}
for (size_t i = 0; i <= N_BITS; ++i) {
const size_t count = zix_bitset_count_up_to(b, t, i);
- if (count != i) {
- return test_fail(
- "Count to %" PRIuPTR " is %" PRIuPTR " != %" PRIuPTR "\n", i, count, i);
- }
+ assert(count == i);
}
for (size_t i = 0; i <= N_BITS; ++i) {
if (i < N_BITS) {
zix_bitset_reset(b, t, i);
}
+
const size_t count = zix_bitset_count_up_to(b, t, i);
- if (count != 0) {
- return test_fail(
- "Count to %" PRIuPTR " is %" PRIuPTR " != %d\n", i, count, 0);
- }
+ assert(count == 0);
}
zix_bitset_clear(b, t, N_BITS);
@@ -73,13 +49,8 @@ main(void)
const size_t count = zix_bitset_count_up_to(b, t, i + 1);
const size_t result = MIN(N_BITS / 2, i / 2 + 1);
- if (count != result) {
- return test_fail("Count to %" PRIuPTR " is %" PRIuPTR " != %" PRIuPTR
- "\n",
- i,
- count,
- result);
- }
+
+ assert(count == result);
}
zix_bitset_clear(b, t, N_BITS);
@@ -89,18 +60,9 @@ main(void)
const size_t count = zix_bitset_count_up_to_if(b, t, i);
const size_t result = MIN(N_BITS / 2, i / 2);
- if (count != result) {
- return test_fail("Count to %" PRIuPTR " is %" PRIuPTR " != %" PRIuPTR
- "\n",
- i,
- count,
- result);
- }
+ assert(count == result);
} else {
- if (zix_bitset_count_up_to_if(b, t, i) != (size_t)-1) {
- return test_fail(
- "Got unexpected non-zero count at index %" PRIuPTR "\n", i);
- }
+ assert(zix_bitset_count_up_to_if(b, t, i) == (size_t)-1);
}
}