def test_weights(): s = SummaryStats() s.add(10, 2) assert s.count() == 2 assert s.sum() == 10 x = np.array([1, 2, 3, 4, 5]) s.update(x, 2) assert s.count() == 12 assert s.sum() == x.sum() + 10 s = SummaryStats() x = np.array([1, 2, 3, 4, 5]) s.update(x, x) assert s.count() == x.sum()
def test_add_update_errors(): s = SummaryStats() x = np.array([1, 2, 3]) for c in [-1, 0, np.array([1, 1, -1])]: with pytest.raises(ValueError): s.update(x, c) for c in [-1, 0]: with pytest.raises(ValueError): s.update(1, c) with pytest.raises(ValueError): s.update(x, np.nan) with pytest.raises(ValueError): s.add(1, np.nan)
def test_repr(): s = SummaryStats() assert str(s) == 'SummaryStats<count=0>' s.add(10) assert str(s) == 'SummaryStats<count=1>'