aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_statistics.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2024-06-14 10:21:35 -0500
committerGitHub <noreply@github.com>2024-06-14 10:21:35 -0500
commit41554ef0e0925695544d96a7bc49af1428d6bb6b (patch)
treeca4671d4645c3f240ac0b7325d5f4f5ccdd51218 /Lib/test/test_statistics.py
parent42351c3b9a357ec67135b30ed41f59e6f306ac52 (diff)
downloadcpython-41554ef0e0925695544d96a7bc49af1428d6bb6b.tar.gz
cpython-41554ef0e0925695544d96a7bc49af1428d6bb6b.zip
Stronger tests for the statistics kernel formulas (gh-120506)
Diffstat (limited to 'Lib/test/test_statistics.py')
-rw-r--r--Lib/test/test_statistics.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 0b28459f03d..c374c947e02 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -2434,18 +2434,22 @@ class TestKDE(unittest.TestCase):
data.append(100)
self.assertGreater(f_hat(100), 0.0)
- def test_kde_kernel_invcdfs(self):
+ def test_kde_kernel_specs(self):
+ # White-box test for the kernel formulas in isolation from
+ # their downstream use in kde() and kde_random()
kernel_specs = statistics._kernel_specs
- kde = statistics.kde
# Verify that cdf / invcdf will round trip
xarr = [i/100 for i in range(-100, 101)]
+ parr = [i/1000 + 5/10000 for i in range(1000)]
for kernel, spec in kernel_specs.items():
+ cdf = spec['cdf']
invcdf = spec['invcdf']
with self.subTest(kernel=kernel):
- cdf = kde([0.0], h=1.0, kernel=kernel, cumulative=True)
for x in xarr:
self.assertAlmostEqual(invcdf(cdf(x)), x, places=6)
+ for p in parr:
+ self.assertAlmostEqual(cdf(invcdf(p)), p, places=11)
@support.requires_resource('cpu')
def test_kde_random(self):