| 95 | // against a reader that doesn't skip. |
| 96 | template <typename T> |
| 97 | void TestSkipping(const uint8_t* buffer, const int len, const int bit_width, |
| 98 | const int skip_at, const int skip_count) { |
| 99 | constexpr int MAX_LEN = 512; |
| 100 | DCHECK_LE(len, MAX_LEN); |
| 101 | DCHECK_EQ((skip_at * bit_width) % 8, 0); |
| 102 | DCHECK_EQ((skip_count * bit_width) % 8, 0); |
| 103 | int value_count = len * 8 / bit_width; |
| 104 | |
| 105 | T all_vals[MAX_LEN]; |
| 106 | BatchedBitReader expected_reader(buffer, len); |
| 107 | expected_reader.UnpackBatch(bit_width, value_count, all_vals); |
| 108 | |
| 109 | BatchedBitReader skipping_reader(buffer, len); |
| 110 | T vals[MAX_LEN]; |
| 111 | skipping_reader.UnpackBatch(bit_width, skip_at, vals); |
| 112 | bool skipped = skipping_reader.SkipBatch(bit_width, skip_count); |
| 113 | ASSERT_TRUE(skipped); |
| 114 | skipping_reader.UnpackBatch(bit_width, value_count - skip_count, vals + skip_at); |
| 115 | |
| 116 | for (int i = 0; i < skip_at; ++i) { |
| 117 | EXPECT_EQ(all_vals[i], vals[i]); |
| 118 | } |
| 119 | for (int i = skip_at + skip_count; i < len; ++i) { |
| 120 | EXPECT_EQ(all_vals[i], vals[i - skip_count]); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | TEST(BitArray, TestBoolSkip) { |
| 125 | const int len = 4; |
nothing calls this directly
no test coverage detected