From dc0adb44d8d4a33121deaad398f24b5d8ae36d19 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 23 Nov 2023 10:31:03 -0800 Subject: Add extra tests for `random.binomialvariate` (gh-112325) --- Lib/test/test_random.py | 4 ++++ .../NEWS.d/next/Library/2023-11-22-23-08-47.gh-issue-81620.mfZ2Wf.rst | 1 + 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-11-22-23-08-47.gh-issue-81620.mfZ2Wf.rst diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 50bea7b..b1e4ef4 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -1081,6 +1081,7 @@ class TestDistributions(unittest.TestCase): B(n=1, p=-0.5) # Negative p with self.assertRaises(ValueError): B(n=1, p=1.5) # p > 1.0 + self.assertEqual(B(0, 0.5), 0) # n == 0 self.assertEqual(B(10, 0.0), 0) # p == 0.0 self.assertEqual(B(10, 1.0), 10) # p == 1.0 self.assertTrue(B(1, 0.3) in {0, 1}) # n == 1 fast path @@ -1088,6 +1089,9 @@ class TestDistributions(unittest.TestCase): self.assertTrue(B(1, 0.0) in {0}) # n == 1 fast path self.assertTrue(B(1, 1.0) in {1}) # n == 1 fast path + # BG method very small p + self.assertEqual(B(5, 1e-18), 0) + # BG method p <= 0.5 and n*p=1.25 self.assertTrue(B(5, 0.25) in set(range(6))) diff --git a/Misc/NEWS.d/next/Library/2023-11-22-23-08-47.gh-issue-81620.mfZ2Wf.rst b/Misc/NEWS.d/next/Library/2023-11-22-23-08-47.gh-issue-81620.mfZ2Wf.rst new file mode 100644 index 0000000..ff35806 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-22-23-08-47.gh-issue-81620.mfZ2Wf.rst @@ -0,0 +1 @@ +Add extra tests for :func:`random.binomialvariate` -- cgit v0.12