Skip to content

Commit

Permalink
Adding tests to validate cache item shape
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Dec 12, 2018
1 parent ce8c396 commit 0ee3265
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions test/lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,82 @@ exports.simple = {
},
test: function (test) {
this.items.forEach(i => this.cache.set(i, false));
test.expect(14);
test.expect(68);
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "a", "Should be 'a'");
this.cache.set("e", true);
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "a", "Should be 'a'");
test.equal(this.cache.cache.e.right, null, "Should be 'null'");
test.equal(this.cache.cache.e.left, "d", "Should be 'd'");
test.equal(this.cache.cache.d.right, "e", "Should be 'e'");
test.equal(this.cache.cache.d.left, "c", "Should be 'c'");
test.equal(this.cache.cache.c.right, "d", "Should be 'd'");
test.equal(this.cache.cache.c.left, "b", "Should be 'b'");
test.equal(this.cache.cache.b.right, "c", "Should be 'c'");
test.equal(this.cache.cache.b.left, "a", "Should be 'a'");
test.equal(this.cache.cache.a.right, "b", "Should be 'b'");
test.equal(this.cache.cache.a.left, null, "Should be 'null'");
this.cache.set("a", true);
test.equal(this.cache.first, "a", "Should be 'a'");
test.equal(this.cache.last, "b", "Should be 'b'");
test.equal(this.cache.cache.a.right, null, "Should be 'null'");
test.equal(this.cache.cache.a.left, "e", "Should be 'e'");
test.equal(this.cache.cache.e.right, "a", "Should be 'a'");
test.equal(this.cache.cache.e.left, "d", "Should be 'd'");
test.equal(this.cache.cache.d.right, "e", "Should be 'e'");
test.equal(this.cache.cache.d.left, "c", "Should be 'c'");
test.equal(this.cache.cache.c.right, "d", "Should be 'd'");
test.equal(this.cache.cache.c.left, "b", "Should be 'b'");
test.equal(this.cache.cache.b.right, "c", "Should be 'c'");
test.equal(this.cache.cache.b.left, null, "Should be 'null'");
this.cache.set("e", false);
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "b", "Should be 'b'");
test.equal(this.cache.cache.e.right, null, "Should be 'null'");
test.equal(this.cache.cache.e.left, "a", "Should be 'a'");
test.equal(this.cache.cache.a.right, "e", "Should be 'e'");
test.equal(this.cache.cache.a.left, "d", "Should be 'd'");
test.equal(this.cache.cache.d.right, "a", "Should be 'a'");
test.equal(this.cache.cache.d.left, "c", "Should be 'c'");
test.equal(this.cache.cache.c.right, "d", "Should be 'd'");
test.equal(this.cache.cache.c.left, "b", "Should be 'b'");
test.equal(this.cache.cache.b.right, "c", "Should be 'c'");
test.equal(this.cache.cache.b.left, null, "Should be 'null'");
this.cache.remove("a");
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "b", "Should be 'b'");
test.equal(this.cache.cache.e.right, null, "Should be 'null'");
test.equal(this.cache.cache.e.left, "d", "Should be 'a'");
test.equal(this.cache.cache.d.right, "e", "Should be 'a'");
test.equal(this.cache.cache.d.left, "c", "Should be 'c'");
test.equal(this.cache.cache.c.right, "d", "Should be 'd'");
test.equal(this.cache.cache.c.left, "b", "Should be 'b'");
test.equal(this.cache.cache.b.right, "c", "Should be 'c'");
test.equal(this.cache.cache.b.left, null, "Should be 'null'");
this.cache.evict();
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "c", "Should be 'c'");
test.equal(this.cache.cache.e.right, null, "Should be 'null'");
test.equal(this.cache.cache.e.left, "d", "Should be 'a'");
test.equal(this.cache.cache.d.right, "e", "Should be 'a'");
test.equal(this.cache.cache.d.left, "c", "Should be 'c'");
test.equal(this.cache.cache.c.right, "d", "Should be 'd'");
test.equal(this.cache.cache.c.left, null, "Should be 'null'");
this.cache.evict();
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "d", "Should be 'd'");
this.cache.remove("a");
test.equal(this.cache.cache.e.right, null, "Should be 'null'");
test.equal(this.cache.cache.e.left, "d", "Should be 'a'");
test.equal(this.cache.cache.d.right, "e", "Should be 'a'");
test.equal(this.cache.cache.d.left, null, "Should be 'null'");
this.cache.remove("a"); // no op - repeating assertions
test.equal(this.cache.first, "e", "Should be 'e'");
test.equal(this.cache.last, "d", "Should be 'd'");
test.equal(this.cache.cache.e.right, null, "Should be 'null'");
test.equal(this.cache.cache.e.left, "d", "Should be 'a'");
test.equal(this.cache.cache.d.right, "e", "Should be 'a'");
test.equal(this.cache.cache.d.left, null, "Should be 'null'");
test.done();
}
};

0 comments on commit 0ee3265

Please sign in to comment.