-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
30 lines (21 loc) · 998 Bytes
/
tests.py
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
import pytest
from scipy import stats
from fit_discrete import read_file, distributions, fit_distribution, guess_bounds
@pytest.mark.parametrize("key, expected", [('discrete uniform', 6.591673732008659),
('beta binomial', 6.068425588244196),
('zipfian', 7.86098064513523)])
def test_results(key, expected):
data = read_file('test_data.txt')
bounds = guess_bounds(data)
res = fit_distribution(data, distributions[key], bounds[key])
assert res.success
assert pytest.approx(expected, res.nllf())
def test_bounds():
data = stats.randint.rvs(low=0, high=10, size=100)
bounds = guess_bounds(data)
res = fit_distribution(data, stats.randint, bounds['discrete uniform'])
assert res.success
res = fit_distribution(data, stats.betabinom, bounds['beta binomial'])
assert res.success
res = fit_distribution(data, stats.zipf, bounds['zipfian'])
assert res.success