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