MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_ring_buffer

Function test_ring_buffer

tests/test_RingBuffer.py:6–41  ·  view source on GitHub ↗

Tests that the ring buffer correctly tracks recently inserted values, up to a fixed size, and can be cleared to reset its state.

()

Source from the content-addressed store, hash-verified

4
5
6def test_ring_buffer():
7 """
8 Tests that the ring buffer correctly tracks recently inserted values, up to
9 a fixed size, and can be cleared to reset its state.
10 """
11 buffer = RingBuffer(maxlen=2)
12 assert_equal(buffer.maxlen, 2)
13 assert_equal(len(buffer), 0)
14
15 obj1 = object()
16 obj2 = object()
17
18 # Insert obj1, and test that the length and peek functions return the
19 # correct values: 1 item, and peek at the next slot should return None
20 # since we haven't set it yet.
21 buffer.append(obj1)
22 assert_equal(len(buffer), 1)
23 assert_(buffer.peek() is None)
24
25 # Append obj2, and check that the buffer now has two items. Peeking at
26 # the next slot should wrap around, back to obj1, since we can store only
27 # two items.
28 buffer.append(obj2)
29 assert_equal(len(buffer), 2)
30 assert_(buffer.peek() is obj1)
31
32 # Skip the next slot. This should not remove anything, but should cause
33 # ``peek()`` to now point to the slot occupied by obj2.
34 buffer.skip()
35 assert_equal(len(buffer), 2)
36 assert_(buffer.peek() is obj2)
37
38 # Clearing the buffer should reset its entire state.
39 buffer.clear()
40 assert_equal(buffer.maxlen, 2)
41 assert_equal(len(buffer), 0)

Callers

nothing calls this directly

Calls 5

appendMethod · 0.95
peekMethod · 0.95
skipMethod · 0.95
clearMethod · 0.95
RingBufferClass · 0.90

Tested by

no test coverage detected