1 #include "jitcs_int_adt_bitmap.h"
8 static void test(UnitTest
& t
) {
11 t
.check("empty/size", bmp
.bitSize() == 0 && bmp2
.bitSize() == 0);
13 const size_t data
[5] = {0x12345678, 0xdeadbeef, 0x1, ~(size_t)0, 0};
14 const size_t bitcount
= ConstBitSlice::E_BitsPerWord
* 4 + 15;
15 ConstBitSlice
bmp3(data
, bitcount
);
16 t
.check("5 words/size&ptr", bmp3
.bitSize() == bitcount
&& bmp3
.ptr() == data
17 && bmp3
.wordSize() == 5);
18 t
.check("isValidIndex", bmp3
.isValidIndex(0) && bmp3
.isValidIndex(bitcount
- 1)
19 && !bmp3
.isValidIndex(bitcount
));
20 t
.check("getWordForIndex", bmp3
.getWordForIndex(ConstBitSlice::E_BitsPerWord
) == 0xdeadbeef);
21 t
.check("bit test", bmp3
.test(ConstBitSlice::E_BitsPerWord
* 3 + 12) == true
22 && bmp3
.test(ConstBitSlice::E_BitsPerWord
* 4 + 12) == false);
24 size_t data2
[5] = {0, 0, 0, 0, 0};
25 BitSlice bmp4
= BitSlice(data2
, bitcount
);
27 t
.check("copyFrom", bmp4
.equals(bmp3
));
28 bmp4
.mark(bitcount
- 1);
29 t
.check("isSubsetOf", bmp3
.isSubsetOf(bmp3
)
30 && bmp3
.isSubsetOf(bmp4
) && !bmp4
.isSubsetOf(bmp3
));
32 bool oldvalue
= bmp4
.test(0);
34 t
.check("bit set", bmp4
.test(0));
36 t
.check("bit clear", !bmp4
.test(0));
37 t
.check("testAndMark", !bmp4
.testAndMark(0) && bmp4
.test(0));
38 t
.check("testAndClear", bmp4
.testAndClear(0) && !bmp4
.test(0));
39 t
.check("testAndComplement", !bmp4
.testAndComplement(0) && bmp4
.test(0));
40 t
.check("testAndComplement2", bmp4
.testAndComplement(0) && !bmp4
.test(0));
42 t
.check("clearAll", bmp4
.countSetBits() == 0);
44 t
.check("setAll", bmp4
.countSetBits() == bitcount
);
46 size_t data3
[5] = {0xabba, 0xdeaf, 0xbeeb0b, 0xbabee, 0xcaca0};
47 BitSlice
bmp5(data3
, bitcount
);
49 bmp4
.intersectWith(bmp5
);
50 t
.check("intersectWith", bmp4
.getWordForIndex(0) == (0xabba & 0x12345678));
53 t
.check("uniteWith", bmp4
.getWordForIndex(0) == (0xabba | 0x12345678));
56 t
.check("clearFrom", bmp4
.getWordForIndex(0) == (~0xabba & 0x12345678));
59 BitSlice::BitEnumerator
it0(bmpit
.enumBits());
60 t
.check("BitmapIterator/empty", it0
.isEmpty());
62 size_t data4
[5] = {0, 0, 0, 0, 0};
63 BitSlice
bmpit2(data4
, bitcount
);
64 BitSlice::BitEnumerator
it1(bmpit2
.enumBits());
65 t
.check("BitmapIterator/zero bitmap", it1
.isEmpty());
69 bmpit2
.mark(bitcount
- 1);
70 BitSlice::BitEnumerator
it2(bmpit2
.enumBits());
71 t
.check("BitmapIterator/iteration1", !it2
.isEmpty() && *it2
== 0);
73 t
.check("BitmapIterator/iteration2", !it2
.isEmpty() && *it2
== 31);
75 t
.check("BitmapIterator/iteration3", !it2
.isEmpty() && *it2
== bitcount
- 1);
77 t
.check("BitmapIterator/iteration4", it2
.isEmpty());
81 static UnitTestRun
_1("ADT/Bitmap", test
);