| 70 | const int BITMAP_ITEMS = 1000000; |
| 71 | |
| 72 | void testBitmap() |
| 73 | { |
| 74 | MallocAllocator temp; |
| 75 | |
| 76 | printf("Test Firebird::SparseBitmap\n"); |
| 77 | |
| 78 | printf("Fill arrays with test data (%d items)...", BITMAP_ITEMS); |
| 79 | Vector<int, BITMAP_ITEMS> v1; |
| 80 | int n = 0; |
| 81 | int i; |
| 82 | for (i = 0; i < BITMAP_ITEMS; i++) { |
| 83 | n = n * 45578 - 17651; |
| 84 | // Fill it with quasi-random values in range 0...BITMAP_ITEMS-1 |
| 85 | v1.add(((i + n) % BITMAP_ITEMS + BITMAP_ITEMS) / 2); |
| 86 | } |
| 87 | |
| 88 | Vector<int, BITMAP_ITEMS> v2; |
| 89 | for (i = 0; i < BITMAP_ITEMS; i++) { |
| 90 | n = n * 45578 - 17651; |
| 91 | // Fill it with quasi-random values in range 0...BITMAP_ITEMS-1 |
| 92 | v2.add(((i + n) % BITMAP_ITEMS + BITMAP_ITEMS) / 2); |
| 93 | } |
| 94 | printf(" DONE\n"); |
| 95 | |
| 96 | Firebird::BePlusTree<int> tree(&temp), tree2(&temp); |
| 97 | SparseBitmap<ULONG> bitmap(*getDefaultMemoryPool()), bitmap2(*getDefaultMemoryPool()); |
| 98 | |
| 99 | printf("Verify SET, TEST operations"); |
| 100 | // Check set, test |
| 101 | for (i = 0; i < BITMAP_ITEMS; i++) { |
| 102 | if (!tree.add(v1[i])) |
| 103 | if (!bitmap.test(v1[i])) |
| 104 | fb_assert(false); |
| 105 | bitmap.set(v1[i]); |
| 106 | } |
| 107 | printf(" DONE\n"); |
| 108 | |
| 109 | printf("Check correctness of all bits in bitmap"); |
| 110 | for (i = -10; i < BITMAP_ITEMS + 10; i++) { |
| 111 | if (bitmap.test(i) != tree.locate(i)) |
| 112 | fb_assert(false); |
| 113 | } |
| 114 | printf(" DONE\n"); |
| 115 | |
| 116 | printf("Verify CLEAR(V) operation for correctness"); |
| 117 | for (i = 0; i < BITMAP_ITEMS; i++) { |
| 118 | if (tree.locate(v1[i])) { |
| 119 | bool result = bitmap.clear(v1[i]); |
| 120 | tree.fastRemove(); |
| 121 | fb_assert(result == true); |
| 122 | } |
| 123 | else { |
| 124 | bool result = bitmap.clear(v1[i]); |
| 125 | fb_assert(result == false); |
| 126 | } |
| 127 | } |
| 128 | printf(" DONE\n"); |
| 129 |
no test coverage detected