a b/tests/edgepy/test_stats.py
1
import unittest
2
3
from inmoose.edgepy import pnbinom, qnbinom
4
5
6
class test_nbinom(unittest.TestCase):
7
    def test_nbinom(self):
8
        for i in range(10):
9
            hi = pnbinom(i, size=5, prob=0.2, lower_tail=False)
10
            lo = pnbinom(i, size=5, prob=0.2, lower_tail=True)
11
            self.assertEqual(hi, 1.0 - lo)
12
            self.assertEqual(i, qnbinom(hi, size=5, prob=0.2, lower_tail=False))
13
            self.assertEqual(i, qnbinom(lo, size=5, prob=0.2, lower_tail=True))
14
15
            hi = pnbinom(i, size=5, mu=4, lower_tail=False)
16
            lo = pnbinom(i, size=5, mu=4, lower_tail=True)
17
            self.assertAlmostEqual(hi, 1.0 - lo)
18
            self.assertEqual(i, qnbinom(hi, size=5, mu=4, lower_tail=False))
19
            self.assertEqual(i, qnbinom(lo, size=5, mu=4, lower_tail=True))
20
21
        ctxt = self.assertRaisesRegex(
22
            ValueError, expected_regex="exactly one of prob and mu must be provided"
23
        )
24
        with ctxt:
25
            pnbinom(42, size=5, prob=0.5, mu=4)
26
        with ctxt:
27
            qnbinom(42, size=5, prob=0.5, mu=4)
28
        with ctxt:
29
            pnbinom(42, size=5)
30
        with ctxt:
31
            qnbinom(42, size=5)