Skip to content

Commit

Permalink
(#22) Fixed removing to modify count
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Tang committed Feb 13, 2014
1 parent 3de7704 commit d22f609
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/LinkedHashMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@
var key = node.getKey();
if (node === this.private.first) {
this.private.first = this.private.first.getNext();
this.private.first.setPrevious(null);
if (this.private.first instanceof Node) {
this.private.first.setPrevious(null);
}
} else if (node === this.private.last) {
this.private.last = this.private.last.getPrevious();
this.private.last.setNext(null);
} else {
node.getPrevious().setNext(node.getNext());
node.getNext().setPrevious(node.getPrevious());
}
this.private.count--;
delete this.private.hashMap[key];
}
};
Expand Down
7 changes: 7 additions & 0 deletions test/spec/LinkedHashMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@
expect(first.getPrevious()).toEqual(null);
});

it('should be able to delete all entries', function removeFirstWithRemove() {
list.remove(0);
list.remove(1);
list.remove(2);
expect(list.isEmpty()).toEqual(true);
});

it('should be able to remove the last entry', function removeLast() {
list.removeLast();
var last = list.getLast();
Expand Down

0 comments on commit d22f609

Please sign in to comment.