| 181 | } |
| 182 | |
| 183 | static void CheckUniform(SimplePhilox* rnd, WeightedPicker* picker, |
| 184 | int trials) { |
| 185 | const int size = picker->num_elements(); |
| 186 | int* count = new int[size]; |
| 187 | memset(count, 0, sizeof(count[0]) * size); |
| 188 | for (int i = 0; i < size * trials; i++) { |
| 189 | const int elem = picker->Pick(rnd); |
| 190 | EXPECT_GE(elem, 0); |
| 191 | EXPECT_LT(elem, size); |
| 192 | count[elem]++; |
| 193 | } |
| 194 | const int expected_min = int(0.9 * trials); |
| 195 | const int expected_max = int(1.1 * trials); |
| 196 | for (int i = 0; i < size; i++) { |
| 197 | EXPECT_GE(count[i], expected_min); |
| 198 | EXPECT_LE(count[i], expected_max); |
| 199 | } |
| 200 | delete[] count; |
| 201 | } |
| 202 | |
| 203 | static void CheckSkewed(SimplePhilox* rnd, WeightedPicker* picker, int trials) { |
| 204 | const int size = picker->num_elements(); |
no test coverage detected