示例#1
0
def test_cv_update_batch():
    cv1 = ContinuousValue()
    cv2 = ContinuousValue()
    nums = [random() for i in range(10)]

    for n in nums:
        cv1.update(n)

    cv2.update_batch(nums)

    assert cv1.unbiased_mean() == cv2.unbiased_mean()
    assert cv1.biased_std() == cv2.biased_std()
示例#2
0
def test_cv_combine():
    cv1 = ContinuousValue()
    with pytest.raises(ValueError):
        cv1.combine(3)

    cv2 = ContinuousValue()
    cv3 = ContinuousValue()

    nums = [normalvariate(0, 1) for _ in range(1000)]

    cv1.update_batch(nums[:500])
    cv2.update_batch(nums[500:])
    cv3.update_batch(nums)

    cv1.combine(cv2)

    assert cv1.num == cv3.num
    assert abs(cv1.mean - cv3.mean) <= 1e-6
    assert abs(cv1.meanSq - cv3.meanSq) <= 1e-6