test: add circular buffer toArray() test
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 21 May 2024 20:50:12 +0000 (22:50 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 21 May 2024 20:50:12 +0000 (22:50 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/circular-buffer.test.mjs

index ec86ca2a4479ff3adb56b60524a20b56c43dff5a..804bb587962aca4c66f9808e923c33d2dd1eef93 100644 (file)
@@ -57,4 +57,15 @@ describe('Circular buffer test suite', t => {
     expect(circularBuffer.items).toMatchObject([5, 6, 3, 4])
     expect(circularBuffer.writeIdx).toBe(2)
   })
+
+  it('Verify that circular buffer toArray() works as intended', () => {
+    const circularBuffer = new CircularBuffer(4)
+    circularBuffer.put(1)
+    circularBuffer.put(2)
+    circularBuffer.put(3)
+    circularBuffer.put(4)
+    circularBuffer.put(5)
+    circularBuffer.put(6)
+    expect(circularBuffer.toArray()).toStrictEqual([5, 6, 3, 4])
+  })
 })