Writes 'num_vals' values with width 'bit_width' and reads them back.
| 108 | |
| 109 | // Writes 'num_vals' values with width 'bit_width' and reads them back. |
| 110 | void TestBitArrayValues(int bit_width, int num_vals) { |
| 111 | const int kTestLen = BitUtil::Ceil<3>(bit_width * num_vals); |
| 112 | const uint64_t mod = bit_width == 64? 1 : 1LL << bit_width; |
| 113 | |
| 114 | faststring buffer(kTestLen); |
| 115 | BitWriter writer(&buffer); |
| 116 | for (int i = 0; i < num_vals; ++i) { |
| 117 | writer.PutValue(i % mod, bit_width); |
| 118 | } |
| 119 | writer.Flush(); |
| 120 | EXPECT_EQ(writer.bytes_written(), kTestLen); |
| 121 | |
| 122 | BitReader reader(buffer.data(), kTestLen); |
| 123 | for (int i = 0; i < num_vals; ++i) { |
| 124 | int64_t val = 0; |
| 125 | bool result = reader.GetValue(bit_width, &val); |
| 126 | EXPECT_TRUE(result); |
| 127 | EXPECT_EQ(val, i % mod); |
| 128 | } |
| 129 | EXPECT_EQ(reader.bytes_left(), 0); |
| 130 | } |
| 131 | |
| 132 | TEST(BitArray, TestValues) { |
| 133 | for (int width = 1; width <= kMaxWidth; ++width) { |
no test coverage detected