docs: refine task statistics description
[poolifier.git] / tests / queue.test.js
... / ...
CommitLineData
1const { expect } = require('expect')
2const { Queue } = require('../lib/queue')
3
4describe('Queue test suite', () => {
5 it('Verify enqueue() behavior', () => {
6 const queue = new Queue()
7 let rtSize = queue.enqueue(1)
8 expect(queue.size).toBe(1)
9 expect(rtSize).toBe(queue.size)
10 expect(queue.head).toBe(0)
11 expect(queue.tail).toBe(1)
12 expect(queue.max).toBe(1)
13 expect(queue.items).toStrictEqual({ 0: 1 })
14 rtSize = queue.enqueue(2)
15 expect(queue.size).toBe(2)
16 expect(rtSize).toBe(queue.size)
17 expect(queue.head).toBe(0)
18 expect(queue.tail).toBe(2)
19 expect(queue.max).toBe(2)
20 expect(queue.items).toStrictEqual({ 0: 1, 1: 2 })
21 rtSize = queue.enqueue(3)
22 expect(queue.size).toBe(3)
23 expect(rtSize).toBe(queue.size)
24 expect(queue.head).toBe(0)
25 expect(queue.tail).toBe(3)
26 expect(queue.max).toBe(3)
27 expect(queue.items).toStrictEqual({ 0: 1, 1: 2, 2: 3 })
28 })
29
30 it('Verify dequeue() behavior', () => {
31 const queue = new Queue()
32 queue.enqueue(1)
33 queue.enqueue(2)
34 queue.enqueue(3)
35 let rtItem = queue.dequeue()
36 expect(queue.size).toBe(2)
37 expect(rtItem).toBe(1)
38 expect(queue.head).toBe(1)
39 expect(queue.tail).toBe(3)
40 expect(queue.max).toBe(3)
41 expect(queue.items).toStrictEqual({ 1: 2, 2: 3 })
42 rtItem = queue.dequeue()
43 expect(queue.size).toBe(1)
44 expect(rtItem).toBe(2)
45 expect(queue.head).toBe(2)
46 expect(queue.tail).toBe(3)
47 expect(queue.max).toBe(3)
48 expect(queue.items).toStrictEqual({ 2: 3 })
49 rtItem = queue.dequeue()
50 expect(queue.size).toBe(0)
51 expect(rtItem).toBe(3)
52 expect(queue.head).toBe(0)
53 expect(queue.tail).toBe(0)
54 expect(queue.max).toBe(3)
55 expect(queue.items).toStrictEqual({})
56 })
57})