Example #1
0
		it("clear/length", function() {
			var q = new collection.Queue(3);

			q.add(100);
			q.add(200);
			assert.deepEqual(q.toArray(), [100, 200]);

			q.clear();
			assert.deepEqual(q.toArray(), []);
			assert.equal(q.length, 0);
		});
Example #2
0
		it("offer", function() {
			var q = new collection.Queue(3);

			assert.equal(q.offer(100), true);
			assert.equal(q.offer(200), true);
			assert.equal(q.offer(300), true);
			assert.deepEqual(q.toArray(), [100, 200, 300]);

			assert.equal(q.offer(400), false);
			assert.deepEqual(q.toArray(), [100, 200, 300]);
		});
Example #3
0
		it("add", function() {
			var q = new collection.Queue(3);

			assert.equal(q.add(100), true);
			assert.equal(q.add(200), true);
			assert.equal(q.add(300), true);
			assert.deepEqual(q.toArray(), [100, 200, 300]);

			assert.throws(function() {
				q.add(400);
			});
			assert.deepEqual(q.toArray(), [100, 200, 300]);
		});
Example #4
0
		it("poll", function() {
			var q = new collection.Queue(3);

			q.add(100);
			q.add(200);
			assert.equal(q.poll(), 100);
			assert.deepEqual(q.toArray(), [200]);

			assert.equal(q.poll(), 200);
			assert.deepEqual(q.toArray(), []);

			assert.isNull(q.poll());
			assert.deepEqual(q.toArray(), []);
		});
Example #5
0
		it("remove", function() {
			var q = new collection.Queue(3);

			q.add(100);
			q.add(200);
			assert.equal(q.remove(), 100);
			assert.deepEqual(q.toArray(), [200]);

			assert.equal(q.remove(), 200);
			assert.deepEqual(q.toArray(), []);

			assert.throws(function() {
				q.remove();
			});
			assert.deepEqual(q.toArray(), []);
		});
Example #6
0
		it("peek", function() {
			var q = new collection.Queue(3);

			q.add(100);
			q.add(200);
			assert.equal(q.element(), 100);
			assert.deepEqual(q.toArray(), [100, 200]);

			q.clear();
			assert.isNull(q.peek());
		});
Example #7
0
		it("element", function() {
			var q = new collection.Queue(3);

			q.add(100);
			q.add(200);
			assert.equal(q.element(), 100);
			assert.deepEqual(q.toArray(), [100, 200]);

			q.clear();
			assert.throws(function() {
				q.element();
			});
		});