diff options
Diffstat (limited to 'test/bitset_test.c')
-rw-r--r-- | test/bitset_test.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/test/bitset_test.c b/test/bitset_test.c index 8fa610f..5482f1b 100644 --- a/test/bitset_test.c +++ b/test/bitset_test.c @@ -20,7 +20,7 @@ #include <stdarg.h> #include <stdio.h> -#define N_BITS 256 +#define N_BITS 256 #define N_ELEMS (ZIX_BITSET_ELEMS(N_BITS)) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -29,64 +29,64 @@ 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; + va_list args; + va_start(args, fmt); + fprintf(stderr, "error: "); + vfprintf(stderr, fmt, args); + va_end(args); + return 1; } int main(void) { - ZixBitset b[N_ELEMS]; - 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"); - } - - 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 %zu != %zu\n", count, i + 1); - } - - if (!zix_bitset_get(b, i)) { - return test_fail("Bit %zu is not set\n", i); - } - } - - 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 %zu is %zu != %zu\n", i, 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 %zu is %zu != %d\n", i, count, 0); - } - } - - zix_bitset_clear(b, t, N_BITS); - for (size_t i = 0; i < N_BITS; i += 2) { - zix_bitset_set(b, t, i); - - 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 %zu is %zu != %zu\n", i, count, result); - } - } - - return 0; + ZixBitset b[N_ELEMS]; + 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"); + } + + 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 %zu != %zu\n", count, i + 1); + } + + if (!zix_bitset_get(b, i)) { + return test_fail("Bit %zu is not set\n", i); + } + } + + 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 %zu is %zu != %zu\n", i, 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 %zu is %zu != %d\n", i, count, 0); + } + } + + zix_bitset_clear(b, t, N_BITS); + for (size_t i = 0; i < N_BITS; i += 2) { + zix_bitset_set(b, t, i); + + 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 %zu is %zu != %zu\n", i, count, result); + } + } + + return 0; } |