Changed current relation from BasicBlock to BasicBlockImpl, and Function
[jitcs.git] / tests / test_adt_bitmap.cpp
blob66b63bfe5fd041a2250dc660485e0e0ec9f2918a
1 #include "jitcs_int_adt_bitmap.h"
2 #include "unittest.h"
4 #include <stdio.h>
6 using namespace jitcs;
8 static void test(UnitTest& t) {
9 ConstBitSlice bmp;
10 BitSlice bmp2;
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);
26 bmp4.copyFrom(bmp3);
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);
33 bmp4.mark(0);
34 t.check("bit set", bmp4.test(0));
35 bmp4.clear(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));
41 bmp4.clearAll();
42 t.check("clearAll", bmp4.countSetBits() == 0);
43 bmp4.setAll();
44 t.check("setAll", bmp4.countSetBits() == bitcount);
46 size_t data3[5] = {0xabba, 0xdeaf, 0xbeeb0b, 0xbabee, 0xcaca0};
47 BitSlice bmp5(data3, bitcount);
48 bmp4.copyFrom(bmp3);
49 bmp4.intersectWith(bmp5);
50 t.check("intersectWith", bmp4.getWordForIndex(0) == (0xabba & 0x12345678));
51 bmp4.copyFrom(bmp3);
52 bmp4.uniteWith(bmp5);
53 t.check("uniteWith", bmp4.getWordForIndex(0) == (0xabba | 0x12345678));
54 bmp4.copyFrom(bmp3);
55 bmp4.clearFrom(bmp5);
56 t.check("clearFrom", bmp4.getWordForIndex(0) == (~0xabba & 0x12345678));
58 BitSlice bmpit;
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());
67 bmpit2.mark(0);
68 bmpit2.mark(31);
69 bmpit2.mark(bitcount - 1);
70 BitSlice::BitEnumerator it2(bmpit2.enumBits());
71 t.check("BitmapIterator/iteration1", !it2.isEmpty() && *it2 == 0);
72 ++it2;
73 t.check("BitmapIterator/iteration2", !it2.isEmpty() && *it2 == 31);
74 ++it2;
75 t.check("BitmapIterator/iteration3", !it2.isEmpty() && *it2 == bitcount - 1);
76 ++it2;
77 t.check("BitmapIterator/iteration4", it2.isEmpty());
81 static UnitTestRun _1("ADT/Bitmap", test);