1 |
|
2 | Queue = require( '../../lib/Queue' )
|
3 | should = require 'should'
|
4 |
|
5 | describe 'queue', ->
|
6 |
|
7 | describe 'constructor', ->
|
8 |
|
9 | it 'should set default values', ->
|
10 |
|
11 | queue = new Queue()
|
12 | queue.data.should.eql []
|
13 | queue.isUnique.should.eql true
|
14 |
|
15 | it 'should allow disabling unique', ->
|
16 |
|
17 | queue = new Queue( false )
|
18 | queue.isUnique.should.eql false
|
19 |
|
20 | describe 'has', ->
|
21 |
|
22 | it 'should return true for items in the queue', ->
|
23 |
|
24 | queue = new Queue()
|
25 | queue.add( 'foo' )
|
26 | queue.add( 'bar' )
|
27 | queue.has( 'foo' ).should.eql true
|
28 | queue.has( 'baz' ).should.eql false
|
29 |
|
30 | describe 'count', ->
|
31 |
|
32 | it 'should return queue length', ->
|
33 |
|
34 | queue = new Queue()
|
35 | queue.add( 'foo' )
|
36 | queue.add( 'bar' )
|
37 | queue.count().should.eql 2
|
38 |
|
39 | describe 'add', ->
|
40 |
|
41 | it 'should add once when unique', ->
|
42 |
|
43 | queue = new Queue( true )
|
44 | queue.add( 'foo' )
|
45 | queue.count().should.eql 1
|
46 | queue.add( 'foo' )
|
47 | queue.count().should.eql 1
|
48 |
|
49 | it 'should add twice when not unique', ->
|
50 |
|
51 | queue = new Queue( false )
|
52 | queue.add( 'foo' )
|
53 | queue.count().should.eql 1
|
54 | queue.add( 'foo' )
|
55 | queue.count().should.eql 2
|
56 |
|
57 | describe 'remove', ->
|
58 |
|
59 | it 'should remove all when unique', ->
|
60 |
|
61 | queue = new Queue( true )
|
62 | queue.add( 'foo' )
|
63 | queue.add( 'foo' )
|
64 | queue.count().should.eql 1
|
65 | queue.remove( 'foo' )
|
66 | queue.count().should.eql 0
|
67 |
|
68 | it 'should remove one when not unique', ->
|
69 |
|
70 | queue = new Queue( false )
|
71 | queue.add( 'foo' )
|
72 | queue.add( 'foo' )
|
73 | queue.count().should.eql 2
|
74 | queue.remove( 'foo' )
|
75 | queue.count().should.eql 1
|
76 | queue.remove( 'goo' )
|
77 | queue.count().should.eql 1
|
78 |
|
79 | describe 'shift', ->
|
80 |
|
81 | it 'should remove an element from the beginning of an array', ->
|
82 |
|
83 | queue = new Queue( false )
|
84 | queue.add( 'foo' )
|
85 | queue.add( 'bar' )
|
86 | queue.count().should.eql 2
|
87 | queue.shift().should.eql 'foo'
|
88 | queue.count().should.eql 1
|
89 |
|
90 | describe 'pop', ->
|
91 |
|
92 | it 'should remove an element from the end of an array', ->
|
93 |
|
94 | queue = new Queue( false )
|
95 | queue.add( 'foo' )
|
96 | queue.add( 'bar' )
|
97 | queue.count().should.eql 2
|
98 | queue.pop().should.eql 'bar'
|
99 | queue.count().should.eql 1
|
100 |
|
101 | describe 'adding things twice', ->
|
102 |
|
103 | it 'should not allow you to add things twice when unique', ->
|
104 |
|
105 | queue = new Queue( true )
|
106 | queue.add( 'foo' )
|
107 | queue.count().should.eql 1
|
108 | queue.shift()
|
109 | queue.count().should.eql 0
|
110 | queue.add( 'foo' )
|
111 | queue.count().should.eql 0
|
112 |
|
113 | it 'should not allow you to add things twice when not unique', ->
|
114 |
|
115 | queue = new Queue( false )
|
116 | queue.add( 'foo' )
|
117 | queue.count().should.eql 1
|
118 | queue.shift()
|
119 | queue.count().should.eql 0
|
120 | queue.add( 'foo' )
|
121 | queue.count().should.eql 1 |
\ | No newline at end of file |