Skip to content
Permalink
Browse files
bugfix: handled acessing last element of an empty queue
  • Loading branch information
hbarcelos committed Feb 5, 2020
1 parent d67fdf6 commit b478170b61f23b8ac8ed865624cfd22b3f6f68a0
Showing 2 changed files with 10 additions and 0 deletions.
@@ -25,6 +25,10 @@ class RoundLinkedQueue {
}

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

return this._last.data;
}

@@ -122,5 +122,11 @@ describe("Round-Queue", () => {

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

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

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

0 comments on commit b478170

Please sign in to comment.