| 207 | |
| 208 | template <class Op, typename NextWordFunc> |
| 209 | void CheckBinaryBitBlockOp(NextWordFunc&& get_next_word) { |
| 210 | const int64_t nbytes = 1024; |
| 211 | auto left = *AllocateBuffer(nbytes); |
| 212 | auto right = *AllocateBuffer(nbytes); |
| 213 | random_bytes(nbytes, 0, left->mutable_data()); |
| 214 | random_bytes(nbytes, 0, right->mutable_data()); |
| 215 | |
| 216 | auto CheckWithOffsets = [&](int left_offset, int right_offset) { |
| 217 | int64_t overlap_length = nbytes * 8 - std::max(left_offset, right_offset); |
| 218 | BinaryBitBlockCounter counter(left->data(), left_offset, right->data(), right_offset, |
| 219 | overlap_length); |
| 220 | int64_t position = 0; |
| 221 | do { |
| 222 | BitBlockCount block = get_next_word(&counter); |
| 223 | int expected_popcount = 0; |
| 224 | for (int j = 0; j < block.length; ++j) { |
| 225 | expected_popcount += static_cast<int>( |
| 226 | Op::Call(bit_util::GetBit(left->data(), position + left_offset + j), |
| 227 | bit_util::GetBit(right->data(), position + right_offset + j))); |
| 228 | } |
| 229 | ASSERT_EQ(block.popcount, expected_popcount); |
| 230 | position += block.length; |
| 231 | } while (position < overlap_length); |
| 232 | // We made it through all the data |
| 233 | ASSERT_EQ(position, overlap_length); |
| 234 | |
| 235 | BitBlockCount block = get_next_word(&counter); |
| 236 | ASSERT_EQ(block.length, 0); |
| 237 | ASSERT_EQ(block.popcount, 0); |
| 238 | }; |
| 239 | |
| 240 | for (int left_i = 0; left_i < 8; ++left_i) { |
| 241 | for (int right_i = 0; right_i < 8; ++right_i) { |
| 242 | CheckWithOffsets(left_i, right_i); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | TEST(TestBinaryBitBlockCounter, NextAndWord) { |
| 248 | CheckBinaryBitBlockOp<detail::BitBlockAnd>( |
nothing calls this directly
no test coverage detected