Skip to content
Permalink
Browse files

feature: added initial implementation of .remove() method

  • Loading branch information
hbarcelos committed Feb 5, 2020
1 parent 96d9680 commit e87c31130a955561c8a552042102a42642ac25ec
Showing with 28 additions and 0 deletions.
  1. +9 −0 round-linked-queue.js
  2. +19 −0 round-linked-queue.test.js
@@ -49,6 +49,15 @@ class RoundLinkedQueue {

return removedElement;
}

remove() {
const removedElement = this.first;

this._first = this._first.next;
this._length -= 1;

return removedElement;
}
}

module.exports = RoundLinkedQueue;
@@ -90,4 +90,23 @@ describe("Round-Queue", () => {
expect(result).to.equal(undefined, "should not return an element");
});
});

describe("When removing elements", () => {
it("Should remove the first element of a non-empty queue", () => {
const queue = new RoundQueue(3);
queue.add(1);
queue.add(2);
queue.add(3);
const lengthBefore = queue.length;

const result = queue.remove();

const lengthAfter = queue.length;

expect(lengthAfter).to.equal(lengthBefore - 1, "length should decrease by 1");
expect(result).to.equal(1, "first element should the one being removed");
expect(queue.first).to.equal(2, "should shift the second element to the head of the queue");
expect(queue.last).to.equal(3, "should not change the last element");
});
});
});

0 comments on commit e87c311

Please sign in to comment.
You can’t perform that action at this time.