Skip to content

Commit 12182dc

Browse files
committed
Fix tests
1 parent b149202 commit 12182dc

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

‎Lib/test/test_statistics.py‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,29 +2647,32 @@ def test_equal_inputs(self):
26472647
self.assertEqual(quantiles(data, method='inclusive'),
26482648
[10.0, 10.0, 10.0])
26492649

2650-
def test_monotonic_with_duplicate_floats(self):
2650+
@support.subTests("x", [
2651+
math.pi, # irrational
2652+
1.2, # simple non-integer decimal
2653+
1/3, # repeating binary fraction
2654+
0.1, # non-exact decimal
2655+
2.0, # exact power of two
2656+
1e300, # large magnitude
2657+
1e-300, # small magnitude
2658+
float.fromhex('0x1.fffffffffffffp+1023'), # near max float
2659+
sys.float_info.min, # smallest normal
2660+
float('inf'),
2661+
float('-inf'),
2662+
])
2663+
@support.subTests("method", ["inclusive", "exclusive"])
2664+
def test_monotonic_with_duplicate_floats(self, x, method):
26512665
quantiles = statistics.quantiles
2652-
for x in (3.141592653589793, # irrational-ish
2653-
1/3, # repeating binary fraction
2654-
0.1, # non-exact decimal
2655-
2.0, # exact power of two
2656-
1e300, # large magnitude
2657-
1e-300, # small magnitude
2658-
float.fromhex('0x1.fffffffffffffp+1023'), # near max float
2659-
sys.float_info.min, # smallest normal
2660-
float('inf'),
2661-
float('-inf'),
2662-
):
2663-
for method in ('exclusive', 'inclusive'):
2664-
for n in range(2, 20):
2665-
with self.subTest(x=x, n=n, method=method):
2666-
result = quantiles([x, x], n=n, method=method)
2667-
self.assertEqual(result, sorted(result))
2668-
self.assertTrue(all(v == x for v in result))
2666+
for n in range(2, 20):
2667+
result = quantiles([x, x], n=n, method=method)
2668+
self.assertListEqual(result, sorted(result))
2669+
self.assertSetEqual(set(result), {x})
26692670

2671+
def test_monotonic_with_adjacent_floats(self):
2672+
quantiles = statistics.quantiles
26702673
result = quantiles([0.09999999999999999, 0.1, 0.1],
26712674
n=9, method='inclusive')
2672-
self.assertEqual(result, sorted(result))
2675+
self.assertListEqual(result, sorted(result))
26732676

26742677
def test_mixed_types(self):
26752678
data = [Fraction(1, 2), 0.5, 2.0]

0 commit comments

Comments
 (0)