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