-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlru_replacer_test.go
59 lines (45 loc) · 1014 Bytes
/
lru_replacer_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
package buff
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testReplacer(t *testing.T, r Replacer) {
r.Unpin(1)
r.Unpin(2)
r.Unpin(3)
r.Unpin(4)
r.Unpin(5)
r.Unpin(6)
r.Unpin(1)
assert.Equal(t, 6, r.Size())
var (
evictedFrame int
evicted bool
)
evictedFrame, evicted = r.Victim()
assert.True(t, evicted)
assert.Equal(t, 1, evictedFrame)
evictedFrame, evicted = r.Victim()
assert.True(t, evicted)
assert.Equal(t, 2, evictedFrame)
evictedFrame, evicted = r.Victim()
assert.True(t, evicted)
assert.Equal(t, 3, evictedFrame)
r.Pin(3)
r.Pin(4)
assert.Equal(t, 2, r.Size())
r.Unpin(4)
evictedFrame, evicted = r.Victim()
assert.True(t, evicted)
assert.Equal(t, 5, evictedFrame)
evictedFrame, evicted = r.Victim()
assert.True(t, evicted)
assert.Equal(t, 6, evictedFrame)
evictedFrame, evicted = r.Victim()
assert.True(t, evicted)
assert.Equal(t, 4, evictedFrame)
}
func Test_LRUReplacer(t *testing.T) {
r := NewLRUReplacer(7)
testReplacer(t, r)
}