diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2023-10-01 04:35:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-01 04:35:54 (GMT) |
commit | 62405c7867b03730f0d278ea845855692d262d44 (patch) | |
tree | a5e220ee8d106b2ea59ed23031401228c6cf25a0 /Lib/test/test_statistics.py | |
parent | a46e96076898d126c9f276aef1934195aac34b4e (diff) | |
download | cpython-62405c7867b03730f0d278ea845855692d262d44.zip cpython-62405c7867b03730f0d278ea845855692d262d44.tar.gz cpython-62405c7867b03730f0d278ea845855692d262d44.tar.bz2 |
gh-110150: Fix base case handling in quantiles() (gh-110151)
Diffstat (limited to 'Lib/test/test_statistics.py')
-rw-r--r-- | Lib/test/test_statistics.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index f9b0ac2..b24fc3c 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -2454,6 +2454,11 @@ class TestQuantiles(unittest.TestCase): data = random.choices(range(100), k=k) q1, q2, q3 = quantiles(data, method='inclusive') self.assertEqual(q2, statistics.median(data)) + # Base case with a single data point: When estimating quantiles from + # a sample, we want to be able to add one sample point at a time, + # getting increasingly better estimates. + self.assertEqual(quantiles([10], n=4), [10.0, 10.0, 10.0]) + self.assertEqual(quantiles([10], n=4, method='exclusive'), [10.0, 10.0, 10.0]) def test_equal_inputs(self): quantiles = statistics.quantiles @@ -2504,7 +2509,7 @@ class TestQuantiles(unittest.TestCase): with self.assertRaises(ValueError): quantiles([10, 20, 30], method='X') # method is unknown with self.assertRaises(StatisticsError): - quantiles([10], n=4) # not enough data points + quantiles([], n=4) # not enough data points with self.assertRaises(TypeError): quantiles([10, None, 30], n=4) # data is non-numeric |