]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add extra tests for `random.binomialvariate` (gh-112325)
authorTian Gao <gaogaotiantian@hotmail.com>
Thu, 23 Nov 2023 18:31:03 +0000 (10:31 -0800)
committerGitHub <noreply@github.com>
Thu, 23 Nov 2023 18:31:03 +0000 (12:31 -0600)
Lib/test/test_random.py
Misc/NEWS.d/next/Library/2023-11-22-23-08-47.gh-issue-81620.mfZ2Wf.rst [new file with mode: 0644]

index 50bea7be6d54c7ee99ad43d6126c42093163b2e9..b1e4ef4197d130896028364d4aafe64901e4b675 100644 (file)
@@ -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 (file)
index 0000000..ff35806
--- /dev/null
@@ -0,0 +1 @@
+Add extra tests for :func:`random.binomialvariate`