コード例 #1
0
def test_rolling_mean_returns_nan():
    """
    Tests for rolling mean class.
    """

    mean_buffer = reg.RollingMean(vector_size=3, buffer_size=5)

    assert np.isnan(mean_buffer.getmean()).all
コード例 #2
0
def test_rolling_mean_single_value():
    """
    Test rolling mean returns vector value for single entry
    """
    vector = [5.4, 1.2, 3.4]

    mean_buffer = reg.RollingMean(vector_size=3, buffer_size=5)

    mean_buffer.pop(vector)

    assert np.allclose(vector, mean_buffer.getmean(), rtol=1e-05, atol=1e-10)
コード例 #3
0
def test_rolling_mean_four_values():
    """
    Test rolling mean returns vector value for single entry
    """
    vector0 = [5.4, 1.2, 3.4]
    vector1 = [7.4, -1.2, -1.4]
    vector2 = [-2.6, 4.2, 2.6]
    vector3 = [9.0, 3.3, 3.6]

    expected_answer0 = [3.4, 1.4, 1.533333]
    expected_answer1 = [4.6, 2.1, 1.6]

    mean_buffer = reg.RollingMean(vector_size=3, buffer_size=3)
    mean_buffer.pop(vector0)
    mean_buffer.pop(vector1)
    mean_buffer.pop(vector2)
    assert np.allclose(expected_answer0, mean_buffer.getmean(), rtol=1e-05,
                       atol=1e-6)

    mean_buffer.pop(vector3)

    assert np.allclose(expected_answer1, mean_buffer.getmean(), rtol=1e-05,
                       atol=1e-10)
コード例 #4
0
def test_rolling_mean_no_buffer():
    """
    Try doing a rolling mean with zero buffer.
    """
    with pytest.raises(ValueError):
        _ = reg.RollingMean(vector_size=3, buffer_size=0)