-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuesSpec.js
74 lines (68 loc) · 2.09 KB
/
queuesSpec.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
72
73
74
var expect = chai.expect
var queue, node;
beforeEach(function(){
queue = new Queue
node = new Node(10)
})
describe("#Queue", function(){
it("contains a first and list property", function(){
expect(queue.first).to.equal(null)
expect(queue.last).to.equal(null)
expect(queue.hasOwnProperty('first')).to.equal(true)
expect(queue.hasOwnProperty('last')).to.equal(true)
});
it("contains a size property that begins at 0", function(){
expect(queue.size).to.equal(0)
expect(queue.hasOwnProperty('size')).to.equal(true)
});
});
describe("#Node", function(){
it("contains a value and next property", function(){
expect(node.value).to.equal(10)
expect(node.next).to.equal(null)
expect(node.hasOwnProperty('value')).to.equal(true)
expect(node.hasOwnProperty('next')).to.equal(true)
});
});
describe("#enqueue", function(){
it("returns the new size of the queue", function(){
expect(queue.enqueue(10)).to.equal(1)
expect(queue.size).to.equal(1)
expect(queue.enqueue(100)).to.equal(2)
expect(queue.size).to.equal(2)
expect(queue.enqueue(1000)).to.equal(3)
expect(queue.size).to.equal(3)
});
it("places the value at the end of the queue", function(){
expect(queue.enqueue(10)).to.equal(1)
expect(queue.first.value).to.equal(10)
expect(queue.last.value).to.equal(10)
queue.enqueue(100)
expect(queue.first.value).to.equal(10)
expect(queue.last.value).to.equal(100)
queue.enqueue(1000)
expect(queue.first.value).to.equal(10)
expect(queue.last.value).to.equal(1000)
});
});
describe("#dequeue", function(){
it("returns the value of the node removed", function(){
queue.enqueue(10);
queue.enqueue(100);
queue.enqueue(1000);
var removed = queue.dequeue()
expect(removed).to.equal(10)
expect(queue.size).to.equal(2)
queue.dequeue()
queue.dequeue()
expect(queue.size).to.equal(0)
});
});
describe("#peek", function(){
it("returns the first value in the queue", function(){
queue.enqueue(10);
queue.enqueue(100);
queue.enqueue(1000);
expect(queue.peek()).to.equal(10)
});
});