-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_test.go
68 lines (62 loc) · 1.28 KB
/
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
package bezier
import (
"fmt"
"testing"
)
type Str struct {
V string
}
func (s *Str) Key() string {
return s.V
}
func TestCacheStr(t *testing.T) {
cah := NewCache(3)
fmt.Println(cah)
cah.Put(&Str{"100"})
fmt.Println(cah)
cah.Put(&Str{"200"})
fmt.Println(cah)
cah.Put(&Str{"300"})
fmt.Println(cah)
cah.Put(&Str{"400"})
fmt.Println(cah)
cah.Put(&Str{"500"})
fmt.Println(cah)
cah.Put(&Str{"600"})
fmt.Println(cah)
cah.Put(&Str{"700"})
fmt.Println(cah)
}
func TestCachePoint(t *testing.T) {
cah := NewCache(3)
fmt.Println(cah)
cah.Put(&Point{100, 100, 0})
fmt.Println(cah)
cah.Put(&Point{200, 200, 0})
fmt.Println(cah)
cah.Put(&Point{300, 300, 0})
fmt.Println(cah)
cah.Put(&Point{400, 400, 0})
fmt.Println(cah)
cah.Put(&Point{500, 500, 0})
fmt.Println(cah)
cah.Put(&Point{600, 600, 0})
fmt.Println(cah)
cah.Put(&Point{700, 700, 0})
fmt.Println(cah)
fmt.Printf("%s: %+v\n", "500-500", cah.Get("500-500"))
}
func TestCacheGet(t *testing.T) {
cah := NewCache(3)
fmt.Printf("%s: %+v\n", "100-100", cah.Get("100-100"))
fmt.Println(cah.Get("100-100"))
cah.Put(&Point{100, 100, 0})
fmt.Printf("%s: %+v\n", "100-100", cah.Get("100-100"))
}
func BenchmarkCacheGet(b *testing.B) {
cah := NewCache(3)
cah.Put(&Str{"key"})
for i := 0; i < b.N; i++ {
cah.Get("key")
}
}