-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
queue.test.js
35 lines (34 loc) · 913 Bytes
/
queue.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as t from './testing.js'
import * as queue from './queue.js'
/**
* @param {t.TestCase} _tc
*/
export const testEnqueueDequeue = _tc => {
const N = 30
/**
* @type {queue.Queue<queue.QueueValue<number>>}
*/
const q = queue.create()
t.assert(queue.isEmpty(q))
t.assert(queue.dequeue(q) === null)
for (let i = 0; i < N; i++) {
queue.enqueue(q, new queue.QueueValue(i))
t.assert(!queue.isEmpty(q))
}
for (let i = 0; i < N; i++) {
const item = queue.dequeue(q)
t.assert(item !== null && item.v === i)
}
t.assert(queue.isEmpty(q))
t.assert(queue.dequeue(q) === null)
for (let i = 0; i < N; i++) {
queue.enqueue(q, new queue.QueueValue(i))
t.assert(!queue.isEmpty(q))
}
for (let i = 0; i < N; i++) {
const item = queue.dequeue(q)
t.assert(item !== null && item.v === i)
}
t.assert(queue.isEmpty(q))
t.assert(queue.dequeue(q) === null)
}