def test_extend(self): r = RingBuffer(5) r.extend([1, 2, 3]) np.testing.assert_equal(r, np.array([1, 2, 3])) r.popleft() r.extend([4, 5, 6]) np.testing.assert_equal(r, np.array([2, 3, 4, 5, 6])) r.extendleft([0, 1]) np.testing.assert_equal(r, np.array([0, 1, 2, 3, 4])) r.extendleft([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]))
def test_pops(self): r = RingBuffer(3) r.append(1) r.appendleft(2) r.append(3) np.testing.assert_equal(r, np.array([2, 1, 3])) self.assertEqual(r.pop(), 3) np.testing.assert_equal(r, np.array([2, 1])) self.assertEqual(r.popleft(), 2) np.testing.assert_equal(r, np.array([1])) # test empty pops empty = RingBuffer(1) with self.assertRaisesRegex(IndexError, "pop from an empty RingBuffer"): empty.pop() with self.assertRaisesRegex(IndexError, "pop from an empty RingBuffer"): empty.popleft()