docs: update benchmarks vs. external pools
[poolifier.git] / tests / queue.test.js
index 93211106650fd2317be2aa22589cb60122bb641e..9bb810d3a9d90464e7253384f8be0e25e4423913 100644 (file)
@@ -7,21 +7,21 @@ describe('Queue test suite', () => {
     let rtSize = queue.enqueue(1)
     expect(queue.size).toBe(1)
     expect(rtSize).toBe(queue.size)
-    expect(queue.head).toBe(0)
-    expect(queue.tail).toBe(1)
-    expect(queue.items).toStrictEqual({ 0: 1 })
+    expect(queue.offset).toBe(0)
+    expect(queue.maxSize).toBe(1)
+    expect(queue.items).toStrictEqual([1])
     rtSize = queue.enqueue(2)
     expect(queue.size).toBe(2)
     expect(rtSize).toBe(queue.size)
-    expect(queue.head).toBe(0)
-    expect(queue.tail).toBe(2)
-    expect(queue.items).toStrictEqual({ 0: 1, 1: 2 })
+    expect(queue.offset).toBe(0)
+    expect(queue.maxSize).toBe(2)
+    expect(queue.items).toStrictEqual([1, 2])
     rtSize = queue.enqueue(3)
     expect(queue.size).toBe(3)
     expect(rtSize).toBe(queue.size)
-    expect(queue.head).toBe(0)
-    expect(queue.tail).toBe(3)
-    expect(queue.items).toStrictEqual({ 0: 1, 1: 2, 2: 3 })
+    expect(queue.offset).toBe(0)
+    expect(queue.maxSize).toBe(3)
+    expect(queue.items).toStrictEqual([1, 2, 3])
   })
 
   it('Verify dequeue() behavior', () => {
@@ -32,20 +32,34 @@ describe('Queue test suite', () => {
     let rtItem = queue.dequeue()
     expect(queue.size).toBe(2)
     expect(rtItem).toBe(1)
-    expect(queue.head).toBe(1)
-    expect(queue.tail).toBe(3)
-    expect(queue.items).toStrictEqual({ 1: 2, 2: 3 })
+    expect(queue.offset).toBe(1)
+    expect(queue.maxSize).toBe(3)
+    expect(queue.items).toStrictEqual([1, 2, 3])
     rtItem = queue.dequeue()
     expect(queue.size).toBe(1)
     expect(rtItem).toBe(2)
-    expect(queue.head).toBe(2)
-    expect(queue.tail).toBe(3)
-    expect(queue.items).toStrictEqual({ 2: 3 })
+    expect(queue.offset).toBe(0)
+    expect(queue.maxSize).toBe(3)
+    expect(queue.items).toStrictEqual([3])
     rtItem = queue.dequeue()
     expect(queue.size).toBe(0)
     expect(rtItem).toBe(3)
-    expect(queue.head).toBe(0)
-    expect(queue.tail).toBe(0)
-    expect(queue.items).toStrictEqual({})
+    expect(queue.offset).toBe(0)
+    expect(queue.maxSize).toBe(3)
+    expect(queue.items).toStrictEqual([])
+  })
+
+  it('Verify clear() behavior', () => {
+    const queue = new Queue()
+    queue.enqueue(1)
+    queue.enqueue(2)
+    queue.enqueue(3)
+    expect(queue.size).toBe(3)
+    expect(queue.maxSize).toBe(3)
+    queue.clear()
+    expect(queue.size).toBe(0)
+    expect(queue.maxSize).toBe(0)
+    expect(queue.items).toStrictEqual([])
+    expect(queue.offset).toBe(0)
   })
 })