| 201 | } |
| 202 | |
| 203 | static void CheckSkewed(SimplePhilox* rnd, WeightedPicker* picker, int trials) { |
| 204 | const int size = picker->num_elements(); |
| 205 | int* count = new int[size]; |
| 206 | memset(count, 0, sizeof(count[0]) * size); |
| 207 | for (int i = 0; i < size * trials; i++) { |
| 208 | const int elem = picker->Pick(rnd); |
| 209 | EXPECT_GE(elem, 0); |
| 210 | EXPECT_LT(elem, size); |
| 211 | count[elem]++; |
| 212 | } |
| 213 | |
| 214 | for (int i = 0; i < size - 1; i++) { |
| 215 | LOG(INFO) << i << ": " << count[i]; |
| 216 | const float ratio = float(count[i + 1]) / float(count[i]); |
| 217 | EXPECT_GE(ratio, 1.6f); |
| 218 | EXPECT_LE(ratio, 2.4f); |
| 219 | } |
| 220 | delete[] count; |
| 221 | } |
| 222 | |
| 223 | static void TestPickAt(int items, const int32* weights) { |
| 224 | WeightedPicker picker(items); |
no test coverage detected