test: Add some tests for bitset_run_count

This commit is contained in:
nick
2013-07-23 17:13:40 +01:00
parent 5c5636b053
commit 1b0fe24529

View File

@@ -2,6 +2,11 @@
#include "bitset.h" #include "bitset.h"
#define assert_bitset_is( map, val ) { \
uint64_t *num = map->bits; \
ck_assert_int_eq( val, *num ); \
}
START_TEST(test_bit_set) START_TEST(test_bit_set)
{ {
uint64_t num = 0; uint64_t num = 0;
@@ -171,6 +176,55 @@ START_TEST( test_bitset_clear )
} }
END_TEST END_TEST
START_TEST( test_bitset_run_count )
{
struct bitset_mapping* map = bitset_alloc( 64, 1 );
uint64_t run;
assert_bitset_is( map, 0x0000000000000000 );
bitset_set_range( map, 0, 32 );
assert_bitset_is( map, 0x00000000ffffffff );
run = bitset_run_count( map, 0, 64 );
ck_assert_int_eq( 32, run );
run = bitset_run_count( map, 0, 16 );
ck_assert_int_eq( 16, run );
run = bitset_run_count( map, 16, 64 );
ck_assert_int_eq( 16, run );
run = bitset_run_count( map, 31, 64 );
ck_assert_int_eq( 1, run );
run = bitset_run_count( map, 32, 64 );
ck_assert_int_eq( 32, run );
run = bitset_run_count( map, 32, 32 );
ck_assert_int_eq( 32, run );
run = bitset_run_count( map, 32, 16 );
ck_assert_int_eq( 16, run );
free( map );
map = bitset_alloc( 6400, 100 );
bitset_set_range( map, 0, 3200 );
run = bitset_run_count( map, 0, 6400 );
ck_assert_int_eq( 3200, run );
run = bitset_run_count( map, 1, 6400 );
ck_assert_int_eq( 3199, run );
run = bitset_run_count( map, 3200, 6400 );
ck_assert_int_eq( 3200, run );
run = bitset_run_count( map, 6500, 6400 );
ck_assert_int_eq( 0, run );
}
END_TEST
Suite* bitset_suite(void) Suite* bitset_suite(void)
{ {
@@ -185,6 +239,7 @@ Suite* bitset_suite(void)
tcase_add_test(tc_bitset, test_bitset); tcase_add_test(tc_bitset, test_bitset);
tcase_add_test(tc_bitset, test_bitset_set); tcase_add_test(tc_bitset, test_bitset_set);
tcase_add_test(tc_bitset, test_bitset_clear); tcase_add_test(tc_bitset, test_bitset_clear);
tcase_add_test(tc_bitset, test_bitset_run_count);
suite_add_tcase(s, tc_bit); suite_add_tcase(s, tc_bit);
suite_add_tcase(s, tc_bitset); suite_add_tcase(s, tc_bitset);