(self)
| 2653 | [10.0, 10.0, 10.0]) |
| 2654 | |
| 2655 | def test_equal_sized_groups(self): |
| 2656 | quantiles = statistics.quantiles |
| 2657 | total = 10_000 |
| 2658 | data = [random.expovariate(0.2) for i in range(total)] |
| 2659 | while len(set(data)) != total: |
| 2660 | data.append(random.expovariate(0.2)) |
| 2661 | data.sort() |
| 2662 | |
| 2663 | # Cases where the group size exactly divides the total |
| 2664 | for n in (1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000): |
| 2665 | group_size = total // n |
| 2666 | self.assertEqual( |
| 2667 | [bisect.bisect(data, q) for q in quantiles(data, n=n)], |
| 2668 | list(range(group_size, total, group_size))) |
| 2669 | |
| 2670 | # When the group sizes can't be exactly equal, they should |
| 2671 | # differ by no more than one |
| 2672 | for n in (13, 19, 59, 109, 211, 571, 1019, 1907, 5261, 9769): |
| 2673 | group_sizes = {total // n, total // n + 1} |
| 2674 | pos = [bisect.bisect(data, q) for q in quantiles(data, n=n)] |
| 2675 | sizes = {q - p for p, q in zip(pos, pos[1:])} |
| 2676 | self.assertTrue(sizes <= group_sizes) |
| 2677 | |
| 2678 | def test_error_cases(self): |
| 2679 | quantiles = statistics.quantiles |
nothing calls this directly
no test coverage detected