Skip to content
Permalink
Browse files

bugfix: handled acessing first element of an empty queue

  • Loading branch information
hbarcelos committed Feb 5, 2020
1 parent f4f8c9a commit d67fdf6006b8ad9918499d9933042dac81ac7cfa
Showing with 12 additions and 0 deletions.
  1. +4 −0 round-linked-queue.js
  2. +8 −0 round-linked-queue.test.js
@@ -17,6 +17,10 @@ class RoundLinkedQueue {
}

get first() {
if (!this._first) {
throw new Error("Cannot access the first element of an empty queue");
}

return this._first.data;
}

@@ -115,4 +115,12 @@ describe("Round-Queue", () => {
expect(() => queue.remove()).to.throw("Cannot remove element from an empty queue");
});
});

describe("When accessing elements", () => {
it("Should throw a proper error when acessing the first element of an empty queue", () => {
const queue = new RoundQueue(3);

expect(() => queue.first).to.throw("Cannot access the first element of an empty queue");
});
});
});

0 comments on commit d67fdf6

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