-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitset_tests.c
61 lines (46 loc) · 1.42 KB
/
bitset_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "bitset.h"
void test_size (void ** state) {
}
void test_bitset (void ** state) {
bitset* bs = bitset_init(128);
assert_int_equal(bs->size, 128);
bitset_set(bs, 0);
bitset_set(bs, 1);
assert_int_equal(bitset_popcnt(bs), 2);
assert_int_equal(bitset_get(bs, 0), 1);
assert_int_equal(bitset_get(bs, 1), 1);
bitset_set(bs, 127);
assert_int_equal(bitset_popcnt(bs), 3);
bitset_toggle(bs, 1);
assert_int_equal(bitset_popcnt(bs), 2);
assert_int_equal(bitset_get(bs, 1), 0);
bitset_toggle(bs, 2);
assert_int_equal(bitset_popcnt(bs), 3);
assert_int_equal(bitset_get(bs, 2), 1);
bitset_clear(bs, 2);
assert_int_equal(bitset_popcnt(bs), 2);
assert_int_equal(bitset_get(bs, 2), 0);
bitset_free(bs);
}
void test_bitset_alloc_size (void ** state) {
assert_int_equal(bitset_alloc_size(1), 1);
assert_int_equal(bitset_alloc_size(32), 1);
assert_int_equal(bitset_alloc_size(64), 1);
assert_int_equal(bitset_alloc_size(65), 2);
assert_int_equal(bitset_alloc_size(128), 2);
assert_int_equal(bitset_alloc_size(129), 3);
}
int main (void)
{
const struct CMUnitTest tests [] =
{
cmocka_unit_test (test_bitset),
};
int count_fail_tests =
cmocka_run_group_tests (tests, NULL, NULL);
return count_fail_tests;
}