-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfu_test.ts
58 lines (45 loc) · 805 Bytes
/
lfu_test.ts
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
57
58
import {
assertEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts"
import { LFUCache } from "./lfu.ts"
Deno.test("should evict", (t) => {
const cache = new LFUCache<string>(3)
cache.set('A', 'a')
cache.set('B', 'b')
cache.set('C', 'c')
assertEquals(cache.toString(), `\
0 A
0 B
0 C`)
cache.set('D', 'd')
assertEquals(cache.toString(), `\
0 A
0 B
0 D`)
cache.get('B')
assertEquals(cache.toString(), `\
1 B
0 A
0 D`)
cache.set('E', 'e')
assertEquals(cache.toString(), `\
1 B
0 A
0 E`)
cache.set('D', 'd2')
assertEquals(cache.toString(), `\
1 B
0 A
0 D`)
assertEquals(cache.get('D'), 'd2')
assertEquals(cache.get('B'), 'b')
assertEquals(cache.toString(), `\
2 B
1 D
0 A`)
cache.set('F', 'f')
assertEquals(cache.toString(), `\
2 B
1 D
0 F`)
})