-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlru.test.js
56 lines (47 loc) · 1.63 KB
/
lru.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const assert = require('assert');
const LRUCache = require('./index');
describe("Testing LRU Cache", () => {
before(() => {
console.log( "Starting all tests" );
});
after(() => {
console.log( "Tests Over" );
});
describe("Test 1", () => {
let Cache = new LRUCache(5);
beforeEach(() => {
Cache.put(1, "k1");
Cache.put(2, "k2");
Cache.put(3, "k3");
})
it("Cache.getAllValues() : Returns [k1, k2, k3]", () => {
let correctRes = ['k1', 'k2', 'k3'];
let actualRes = Cache.getAllValues();
for(let i=0; i < 3; i++){
assert.equal(correctRes[i], actualRes[i]);
}
})
it("Cache.getAllKeys() : Returns [1, 2, 3]", () => {
let correctRes = [1, 2, 3];
let actualRes = Cache.getAllKeys();
for(let i=0; i < 3; i++){
assert.equal(correctRes[i], actualRes[i]);
}
})
it("Cache.getCache() : Returns {1: k1, 2: k2, 3: k3}", () => {
let correctRes = {1: "k1", 2: "k2", 3: "k3"};
let actualRes = Cache.getCache();
for(let i=0; i < 3; i++){
assert.equal(correctRes[i], actualRes[i]);
}
})
it("Cache.getAllValues() : Returns [k1, k2, k3]", () => {
Cache.put(4, 'k4');
let correctRes = ['k1', 'k2', 'k3', 'k4'];
let actualRes = Cache.getAllValues();
for(let i=0; i < 4; i++){
assert.equal(correctRes[i], actualRes[i]);
}
})
})
})