'use strict';

const expect        = require('chai').expect,
      PriorityQueue = require('../../lib/queue/priorityQueue');

describe('priorityQueue tests', function() {

    let priorityQueue = new PriorityQueue();

    describe('enqueue(element, priority)', () => {
        it('should throw an error when trying to queue an element with none valid priority', () => {
            expect(() => priorityQueue.enqueue('test', 'p')).to.throw('element priority should be a number bigger than 0');
        });

        it('should queue elements with priorities', () => {
            priorityQueue.enqueue('john', 2);
            priorityQueue.enqueue('sam', 4);
            priorityQueue.enqueue('samantha', 1);
            priorityQueue.enqueue('rose', 7);
        });
    });

    describe('.length()', () => {
        it('should have length of 4', () => {
            expect(priorityQueue.length()).to.equal(4);
        });
    });

    describe('.front()', () => {
        it('should get the front element', () => {
            expect(priorityQueue.front()).to.equal('samantha');
        });
    });

    describe('.back()', () => {
        it('should get the back element', () => {
            expect(priorityQueue.back()).to.equal('rose');
        });
    });

    describe('.dequeue()', () => {
        it('should dequeue elements by priority', () => {
            expect(priorityQueue.dequeue()).to.equal('samantha');
            expect(priorityQueue.length()).to.equal(3);
            expect(priorityQueue.front()).to.equal('john');

            expect(priorityQueue.dequeue()).to.equal('john');
            expect(priorityQueue.length()).to.equal(2);
            expect(priorityQueue.front()).to.equal('sam');  

            expect(priorityQueue.dequeue()).to.equal('sam');
            expect(priorityQueue.length()).to.equal(1);
            expect(priorityQueue.front()).to.equal('rose');        
        });
    });

    describe('.clear()', () => {
        it('should clear the priorty queue', () => {
            priorityQueue.clear();
            expect(priorityQueue.length()).to.equal(0);
            expect(priorityQueue.isEmpty()).to.equal(true);
        });
    });
});
@@ -1248,32 +1248,238 @@
    %7D);%0A    %7D);%0A%0A
+    describe('toArray()', () =%3E %7B%0A        it('should dequeue all elements', function() %7B%0A            expect(priorityQueue.toArray()).to.deep.equal(%5B'john', 'sam', 'samantha', 'rose'%5D);%0A        %7D);%0A    %7D);%0A%0A
     describe('.d
@@ -2116,32 +2116,192 @@
    %7D);%0A    %7D);%0A%0A
+    describe('.isEmpty()', () =%3E %7B%0A        it('should not be empty', () =%3E %7B%0A            expect(priorityQueue.isEmpty()).to.equal(false);%0A        %7D);%0A    %7D);%0A%0A%0A
     describe('.c

test toArray & isEmpty in PQ