| 163 | |
| 164 | template <typename Int> |
| 165 | void TestUnpackAlternating(UnpackFunc<Int> unpack, const UnpackOptions& opts) { |
| 166 | const auto num_bytes = GetNumBytes(opts.batch_size, opts.bit_width, opts.bit_offset); |
| 167 | |
| 168 | // Pick between two different bit patterns so that we always unpack starting with 1 |
| 169 | const uint8_t byte = opts.bit_offset % 2 == 0 ? 0b10101010 : 0b01010101; |
| 170 | const std::vector<uint8_t> packed(static_cast<std::size_t>(num_bytes), byte); |
| 171 | const auto unpacked = UnpackValues(packed.data(), opts, unpack); |
| 172 | |
| 173 | // Generate alternative bit sequence starting with either 0 or 1 |
| 174 | Int one_zero_value = 0; |
| 175 | Int zero_one_value = 0; |
| 176 | for (int i = 0; i < opts.bit_width; ++i) { |
| 177 | zero_one_value = (zero_one_value << 1) | (i % 2); |
| 178 | one_zero_value = (one_zero_value << 1) | ((i + 1) % 2); |
| 179 | } |
| 180 | |
| 181 | std::vector<Int> expected; |
| 182 | if (opts.bit_width % 2 == 0) { |
| 183 | // For even bit_width, the same pattern repeats every time |
| 184 | expected.resize(static_cast<std::size_t>(opts.batch_size), one_zero_value); |
| 185 | } else { |
| 186 | // For odd bit_width, we alternate a pattern leading with 0 and 1 |
| 187 | for (int i = 0; i < opts.batch_size; ++i) { |
| 188 | expected.push_back(i % 2 == 0 ? zero_one_value : one_zero_value); |
| 189 | } |
| 190 | } |
| 191 | EXPECT_EQ(unpacked, expected); |
| 192 | } |
| 193 | |
| 194 | template <typename Int> |
| 195 | void TestAll(UnpackFunc<Int> unpack) { |
nothing calls this directly
no test coverage detected