Writes 'num_vals' values with width 'bit_width' and reads them back.
| 123 | |
| 124 | // Writes 'num_vals' values with width 'bit_width' and reads them back. |
| 125 | void TestBitArrayValues(int bit_width, int num_vals) { |
| 126 | const int kTestLen = BitUtil::Ceil<3>(bit_width * num_vals); |
| 127 | const uint64_t mod = bit_width == 64? 1 : 1LL << bit_width; |
| 128 | |
| 129 | faststring buffer(kTestLen); |
| 130 | BitWriter writer(&buffer); |
| 131 | for (int i = 0; i < num_vals; ++i) { |
| 132 | writer.PutValue(i % mod, bit_width); |
| 133 | } |
| 134 | writer.Flush(); |
| 135 | EXPECT_EQ(writer.bytes_written(), kTestLen); |
| 136 | |
| 137 | BitReader reader(buffer.data(), kTestLen); |
| 138 | for (int i = 0; i < num_vals; ++i) { |
| 139 | int64_t val = 0; |
| 140 | bool result = reader.GetValue(bit_width, &val); |
| 141 | EXPECT_TRUE(result); |
| 142 | EXPECT_EQ(val, i % mod); |
| 143 | } |
| 144 | EXPECT_EQ(reader.bytes_left(), 0); |
| 145 | } |
| 146 | |
| 147 | TEST(BitArray, TestValues) { |
| 148 | for (int width = 1; width <= kMaxWidth; ++width) { |
no test coverage detected