Exemplo n.º 1
0
def test_getitem():
    r = RingBuffer(5)
    r.extend([1, 2, 3])
    r.extend_left([4, 5])
    expected = np.array([4, 5, 1, 2, 3])
    np.testing.assert_equal(r, expected)

    for i in range(r.maxlen):
        assert expected[i] == r[i]

    ii = [0, 4, 3, 1, 2]
    np.testing.assert_equal(r[ii], expected[ii])
Exemplo n.º 2
0
def test_extend():
    r = RingBuffer(5)
    r.extend([1, 2, 3])
    np.testing.assert_equal(r, np.array([1, 2, 3]))
    r.extend([4, 5, 6])
    np.testing.assert_equal(r, np.array([2, 3, 4, 5, 6]))
    r.extend_left([0, 1])
    np.testing.assert_equal(r, np.array([0, 1, 2, 3, 4]))

    r.extend_left([1, 2, 3, 4, 5, 6, 7])
    np.testing.assert_equal(r, np.array([1, 2, 3, 4, 5]))

    r.extend([1, 2, 3, 4, 5, 6, 7])
    np.testing.assert_equal(r, np.array([3, 4, 5, 6, 7]))