def test_statistic_moment_evaluation(): st = Statistic([1]) assert st.moment(1) == 1 assert st.moment(2) == 1 st.extend([2, 3, 4]) assert st.moment(1) == 2.5 assert st.moment(2) == 7.5
def test_statistic_var(): st = Statistic() with pytest.raises(ValueError) as excinfo: st.var() assert 'no data' in str(excinfo.value).lower() st = Statistic([1]) assert st.var() == 0 st.extend([2, 3]) np.testing.assert_allclose(st.var(), 2 / 3, atol=0.001)
def test_statistic_mean(): st = Statistic() with pytest.raises(ValueError) as excinfo: st.mean() assert 'no data' in str(excinfo.value).lower() st = Statistic([1]) assert st.mean() == 1 st.extend([2, 3]) assert st.mean() == 2
def test_statistic_extend_raises_error_when_noniterable_passed(): st = Statistic() with pytest.raises(TypeError) as excinfo: st.extend(1) assert 'not iterable' in str(excinfo.value).lower()
def test_statistic_extend_adds_all_items(): st = Statistic([1]) st.extend([2, 3]) assert st.as_tuple() == (1, 2, 3)