-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfull2Q_test.go
72 lines (58 loc) · 1.13 KB
/
full2Q_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
package allcache
import (
"github.com/stretchr/testify/suite"
"strconv"
"testing"
)
type suiteNtsFull2Q struct {
suite.Suite
cache *ntsFull2Q[string, int]
}
func TestNtsFull2Q(t *testing.T) {
suite.Run(t, new(suiteNtsFull2Q))
}
func (s *suiteNtsFull2Q) SetupTest() {
s.cache = newNtsFull2Q[string, int](3, 2, 10)
s.cache.put("1", 1)
s.cache.put("2", 2)
s.cache.put("3", 3)
for i := 5; i <= 15; i++ {
s.cache.put(strconv.Itoa(i), i)
}
s.cache.put("1", 1)
s.cache.put("2", 2)
s.cache.put("3", 3)
}
func (s *suiteNtsFull2Q) TestFill() {
r, ok := s.cache.get("1", 0)
s.True(ok)
s.Equal(1, r)
r, ok = s.cache.get("2", 0)
s.True(ok)
s.Equal(2, r)
r, ok = s.cache.get("3", 0)
s.True(ok)
s.Equal(3, r)
r, ok = s.cache.get("14", 0)
s.True(ok)
s.Equal(14, r)
r, ok = s.cache.get("15", 0)
s.True(ok)
s.Equal(15, r)
for i := 5; i < 14; i++ {
r, ok := s.cache.get(strconv.Itoa(i), 0)
s.False(ok)
s.Equal(0, r)
}
}
func (s *suiteNtsFull2Q) TestTSVersion() {
c := NewFull2Q[int, int](3, 2, 10)
c.Put(1, 1)
r, ok := c.Get(1, 0)
s.True(ok)
s.Equal(1, r)
c.Delete(1)
r, ok = c.Get(1, 0)
s.False(ok)
s.Equal(0, r)
}