-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
116 lines (100 loc) · 3.16 KB
/
test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "bitmap.h"
int main(int argc, char *argv[])
{
size_t size;
for (size = 0; size <= 1024; ++size) {
bitmap_t *bitmap = bitmap_create(size);
if (bitmap == NULL) {
if (size == 0) {
continue;
}
fprintf(stderr, " NULL pointer, as size = %ld\n", size);
exit(1);
}
size_t index;
#if 0
printf("\n\n\nbegin set:\n");
for (index = 0; index < 20; ++index) {
printf("index = %ld\n", index);
bitmap->set(bitmap, index);
printf("after set index = %ld, bitmap[%ld] = %d \n",
index, index >> 3, bitmap->bitmap[index >> 3]);
printf("test(bitmap, %ld) = %d\n\n", index, bitmap->test(bitmap, index));
}
printf("\n\n\nbegin clear:\n");
for (index = 0; index < 20; ++index) {
printf("index = %ld\n", index);
bitmap->clear(bitmap, index);
printf("after clear index = %ld, bitmap[%ld] = %d\n",
index, index >> 3, bitmap->bitmap[index >> 3]);
printf("test(bitmap, %ld) = %d\n\n", index, bitmap->test(bitmap, index));
}
#else
#if 0
printf("\n\n\nbegin set:\n");
size_t index;
for (index = 0; index < 20; ++index) {
printf("index = %ld\n", index);
bitmap_set(bitmap, index);
printf("after set index = %ld, bitmap[%ld] = %d \n",
index, index >> 3, bitmap->bitmap[index >> 3]);
printf("test(bitmap, %ld) = %d\n\n", index, bitmap_test(bitmap, index));
}
printf("\n\n\nbegin clear:\n");
for (index = 0; index < 20; ++index) {
printf("index = %ld\n", index);
bitmap_clear(bitmap, index);
printf("after clear index = %ld, bitmap[%ld] = %d\n",
index, index >> 3, bitmap->bitmap[index >> 3]);
printf("test(bitmap, %ld) = %d\n\n", index, bitmap_test(bitmap, index));
}
#endif
#endif
//default bitmap all zeros bits: test api: bitmap_test();
for (index = 0; index <= bitmap->size; ++index)
{
if (bitmap_test(bitmap, index)) {
fprintf(stderr, "bitmap_test() not worked at index: %ld\n", index);
exit(1);
}
}
// test api: bitmap_set();
for (index = 0; index <= bitmap->size; ++index)
{
bitmap_set(bitmap, index);
if (!bitmap_test(bitmap, index)) {
fprintf(stderr, "bitmap_set() not worked at index: %ld\n", index);
exit(1);
}
}
// test api: bitmap_clear();
for (index = 0; index <= bitmap->size; ++index)
{
bitmap_clear(bitmap, index);
if (bitmap_test(bitmap, index)) {
fprintf(stderr, "bitmap_clear() not worked at index: %ld\n", index);
exit(1);
}
}
// test api: bitmap_set_all();
bitmap_set_all(bitmap);
for (index = 0; index <= bitmap->size; ++index)
{
if (!bitmap_test(bitmap, index)) {
fprintf(stderr, "bitmap_set_all() not worked at index: %ld\n", index);
exit(1);
}
}
// test api: bitmap_clear_all()
bitmap_clear_all(bitmap);
for (index = 0; index <= bitmap->size; ++index)
{
if (bitmap_test(bitmap, index)) {
fprintf(stderr, "bitmap_clear_all() not worked at index: %ld\n", index);
exit(1);
}
}
bitmap_destroy(bitmap);
}
return 0;
}