def test_addresses(self): r = RingBuffer(5) r.extend([1, 2, 3]) np.testing.assert_equal(r, np.array([1, 2, 3])) self.assertNotEqual(r.current_address, r.unwrap_address) r.popleft() r.extend([4, 5, 6]) np.testing.assert_equal(r, np.array([2, 3, 4, 5, 6])) self.assertEqual(r.current_address, r.unwrap_address) r.extendleft([0, 1]) np.testing.assert_equal(r, np.array([0, 1, 2, 3, 4])) self.assertEqual(r.current_address, r.unwrap_address) r.extendleft([1, 2, 3, 4, 5, 6, 7]) np.testing.assert_equal(r, np.array([1, 2, 3, 4, 5])) self.assertEqual(r.current_address, r.unwrap_address) r.extend([1, 2, 3, 4, 5, 6, 7]) np.testing.assert_equal(r, np.array([3, 4, 5, 6, 7])) self.assertEqual(r.current_address, r.unwrap_address) r.clear() np.testing.assert_equal(r, np.array([])) np.testing.assert_equal(len(r), 0) self.assertNotEqual(r.current_address, r.unwrap_address)
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, "empty"): empty.pop() with self.assertRaisesRegex(IndexError, "empty"): empty.popleft()