-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
test.js
71 lines (65 loc) · 1.46 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import test from 'ava';
import Queue from './index.js';
test('.enqueue()', t => {
const queue = new Queue();
queue.enqueue('🦄');
t.is(queue.dequeue(), '🦄');
queue.enqueue('🌈');
queue.enqueue('❤️');
t.is(queue.dequeue(), '🌈');
t.is(queue.dequeue(), '❤️');
});
test('.dequeue()', t => {
const queue = new Queue();
t.is(queue.dequeue(), undefined);
t.is(queue.dequeue(), undefined);
queue.enqueue('🦄');
t.is(queue.dequeue(), '🦄');
t.is(queue.dequeue(), undefined);
});
test('.peek()', t => {
const queue = new Queue();
t.is(queue.peek(), undefined);
queue.enqueue('🦄');
t.is(queue.peek(), '🦄');
queue.enqueue('🌈');
t.is(queue.peek(), '🦄');
queue.dequeue();
t.is(queue.peek(), '🌈');
queue.dequeue();
t.is(queue.peek(), undefined);
});
test('.clear()', t => {
const queue = new Queue();
queue.clear();
queue.enqueue(1);
queue.clear();
t.is(queue.size, 0);
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.clear();
t.is(queue.size, 0);
});
test('.size', t => {
const queue = new Queue();
t.is(queue.size, 0);
queue.clear();
t.is(queue.size, 0);
queue.enqueue('🦄');
t.is(queue.size, 1);
queue.enqueue('🦄');
t.is(queue.size, 2);
queue.dequeue();
t.is(queue.size, 1);
queue.dequeue();
t.is(queue.size, 0);
queue.dequeue();
t.is(queue.size, 0);
});
test('iterable', t => {
const queue = new Queue();
queue.enqueue('🦄');
queue.enqueue('🌈');
t.deepEqual([...queue], ['🦄', '🌈']);
});