forked from wufenggirl/LeetCode-in-Golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lru-cache_test.go
executable file
·76 lines (51 loc) · 1.3 KB
/
lru-cache_test.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package problem0146
import (
"testing"
"github.com/stretchr/testify/assert"
)
// capacity is 3
func Test_3(t *testing.T) {
ast := assert.New(t)
cache := Constructor(3)
cache.Put(0, 0)
// [(0,0)]
cache.Put(1, 1)
// [(1,1), (0,0)]
cache.Put(2, 2)
// [(2,2), (1,1), (0,0)]
ast.Equal(1, cache.Get(1), "get 1 from [(2,2), (1,1), (0,0)]")
// [(1,1), (2,2), (0,0)]
cache.Put(3, 3)
// [(3,3), (1,1), (2,2)]
ast.Equal(-1, cache.Get(0), "get 2 from [(3,3), (1,1), (2,2)]")
cache.Put(4, 4)
// [(4,4), (3,3), (1,1)]
ast.Equal(-1, cache.Get(2), "get 1 from [(4,4), (3,3), (1,1)]")
ast.Equal(3, cache.Get(3), "get 3 from [(4,4), (3,3), (1,1)]")
// [(3,3), (4,4), (1,1)]
ast.Equal(3, cache.Get(3), "get 3 from [(3,3), (4,4), (1,1)]")
// [(3,3), (4,4), (1,1)]
ast.Equal(4, cache.Get(4), "get 4 from [(3,3), (4,4), (1,1)]")
// [(4,4), (3,3), (1,1)]
ast.Equal(1, cache.Get(1), "get 4 from [(3,3), (4,4), (1,1)]")
// [(1,1), (4,4), (3,3)]
cache.Put(5, 5)
// [(5,5), (1,1), (4,4)]
}
// capacity is 1
func Test_1(t *testing.T) {
ast := assert.New(t)
cache := Constructor(1)
cache.Put(0, 0)
// [(0,0)]
cache.Put(1, 1)
// [(1,1)]
cache.Put(2, 2)
// [(2,2)]
ast.Equal(-1, cache.Get(1), "get 1 from [(2,2)]")
// [(1,1), (2,2), (0,0)]
cache.Put(3, 3)
// [(3,3)]
cache.Put(3, 33)
// [(3,33)]
}