Skip to content

Commit

Permalink
Merge pull request #2 from spirinvladimir/master
Browse files Browse the repository at this point in the history
add tests for lfu
  • Loading branch information
Evgeny Poberezkin committed Feb 5, 2017
2 parents bf64595 + 8373646 commit bbe4d20
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/algorithms.js
Expand Up @@ -10,7 +10,7 @@ var evictions = module.exports = {
mru: {
created: _ruAccessed,
accessed: _ruAccessed,
evict: __uEvict('accessedAt', -Infinity, false)
evict: __uEvict('accessedAt', -Infinity, false)
},
lfu: {
created: _fuAccessed,
Expand Down
31 changes: 29 additions & 2 deletions lib/algorithms.spec.js
Expand Up @@ -37,7 +37,7 @@ describe('algorithms', function() {
slotSet.get(6) .should.equal('test6');

done();
}); }); }); }); });
}); }); }); }); });
});

it('should evict lru item - the earliest accessed', function (done) {
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('algorithms', function() {
slotSet.put(4, 'test4');

setTimeout(function() {
slotSet.get(3);
slotSet.get(3);
setTimeout(function() {
slotSet.get(4);
setTimeout(function() {
Expand All @@ -144,4 +144,31 @@ describe('algorithms', function() {
}); }); }); }); }); }); }); }); });
});
});

describe('lfu', function() {
beforeEach(function(){
slotSet = new SlotSet(1, algorithms.lfu);
});

it('should evict lfu item - the earliest stored', function () {
slotSet.put(1, 'test1');
slotSet.put(2, 'test2');
should.not.exist(slotSet.get(1));
});

it('accessCount should increase by trigger get()', function () {
var
accessCount = 5,
key = 'some key',
value = 'some value';

slotSet.put(key, value);

for (var count = 1; count < accessCount; count += 1)
slotSet.get(key);

slotSet.slots[key].stat.accessCount .should.equal(accessCount);
});
});

});

0 comments on commit bbe4d20

Please sign in to comment.