test_bdtr.py
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import numpy as np
import scipy.special as sc
import pytest
from numpy.testing import assert_allclose, assert_array_equal, suppress_warnings
class TestBdtr(object):
def test(self):
val = sc.bdtr(0, 1, 0.5)
assert_allclose(val, 0.5)
def test_sum_is_one(self):
val = sc.bdtr([0, 1, 2], 2, 0.5)
assert_array_equal(val, [0.25, 0.75, 1.0])
def test_rounding(self):
double_val = sc.bdtr([0.1, 1.1, 2.1], 2, 0.5)
int_val = sc.bdtr([0, 1, 2], 2, 0.5)
assert_array_equal(double_val, int_val)
@pytest.mark.parametrize('k, n, p', [
(np.inf, 2, 0.5),
(1.0, np.inf, 0.5),
(1.0, 2, np.inf)
])
def test_inf(self, k, n, p):
with suppress_warnings() as sup:
sup.filter(DeprecationWarning)
val = sc.bdtr(k, n, p)
assert np.isnan(val)
def test_domain(self):
val = sc.bdtr(-1.1, 1, 0.5)
assert np.isnan(val)
class TestBdtrc(object):
def test_value(self):
val = sc.bdtrc(0, 1, 0.5)
assert_allclose(val, 0.5)
def test_sum_is_one(self):
val = sc.bdtrc([0, 1, 2], 2, 0.5)
assert_array_equal(val, [0.75, 0.25, 0.0])
def test_rounding(self):
double_val = sc.bdtrc([0.1, 1.1, 2.1], 2, 0.5)
int_val = sc.bdtrc([0, 1, 2], 2, 0.5)
assert_array_equal(double_val, int_val)
@pytest.mark.parametrize('k, n, p', [
(np.inf, 2, 0.5),
(1.0, np.inf, 0.5),
(1.0, 2, np.inf)
])
def test_inf(self, k, n, p):
with suppress_warnings() as sup:
sup.filter(DeprecationWarning)
val = sc.bdtrc(k, n, p)
assert np.isnan(val)
def test_domain(self):
val = sc.bdtrc(-1.1, 1, 0.5)
val2 = sc.bdtrc(2.1, 1, 0.5)
assert np.isnan(val2)
assert_allclose(val, 1.0)
def test_bdtr_bdtrc_sum_to_one(self):
bdtr_vals = sc.bdtr([0, 1, 2], 2, 0.5)
bdtrc_vals = sc.bdtrc([0, 1, 2], 2, 0.5)
vals = bdtr_vals + bdtrc_vals
assert_allclose(vals, [1.0, 1.0, 1.0])
class TestBdtri(object):
def test_value(self):
val = sc.bdtri(0, 1, 0.5)
assert_allclose(val, 0.5)
def test_sum_is_one(self):
val = sc.bdtri([0, 1], 2, 0.5)
actual = np.asarray([1 - 1/np.sqrt(2), 1/np.sqrt(2)])
assert_allclose(val, actual)
def test_rounding(self):
double_val = sc.bdtri([0.1, 1.1], 2, 0.5)
int_val = sc.bdtri([0, 1], 2, 0.5)
assert_allclose(double_val, int_val)
@pytest.mark.parametrize('k, n, p', [
(np.inf, 2, 0.5),
(1.0, np.inf, 0.5),
(1.0, 2, np.inf)
])
def test_inf(self, k, n, p):
with suppress_warnings() as sup:
sup.filter(DeprecationWarning)
val = sc.bdtri(k, n, p)
assert np.isnan(val)
@pytest.mark.parametrize('k, n, p', [
(-1.1, 1, 0.5),
(2.1, 1, 0.5)
])
def test_domain(self, k, n, p):
val = sc.bdtri(k, n, p)
assert np.isnan(val)
def test_bdtr_bdtri_roundtrip(self):
bdtr_vals = sc.bdtr([0, 1, 2], 2, 0.5)
roundtrip_vals = sc.bdtri([0, 1, 2], 2, bdtr_vals)
assert_allclose(roundtrip_vals, [0.5, 0.5, np.nan])