-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps_test.go
85 lines (71 loc) · 1.38 KB
/
maps_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
77
78
79
80
81
82
83
84
85
package maps
import (
"fmt"
"log"
"testing"
)
var (
emptyMaps, populatedMaps, largeMaps Maps
)
func init() {
emptyMaps = Maps{}
populatedMaps = Maps{
"MAP1": &Map{Name: "map1"},
}
largeMaps = Maps{}
for i := 0; i < 1000; i++ {
m, err := largeMaps.New(fmt.Sprintf("map%d", i))
if err != nil {
log.Panic(err)
}
for j := 0; j < 1000; j++ {
err := m.Locations.New(fmt.Sprintf("location%d", i))
if err != nil {
log.Fatal(err)
}
}
}
}
func BenchmarkMaps_Get(b *testing.B) {
for i := 0; i < b.N; i++ {
//noinspection GoUnhandledErrorResult
largeMaps.Get("map1")
}
}
func TestMaps_Get(t *testing.T) {
for _, s := range []string{"map1", "mAp1", "MAP1"} {
if _, err := populatedMaps.Get(s); err != nil {
t.Error(err)
}
}
}
func TestMaps_Get_Default(t *testing.T) {
mm := Maps{}
_, err := mm.New("", "location1")
if err != nil {
t.Fatal(err)
}
for _, s := range []string{"map1", ""} {
if _, err := mm.Get(s); err != nil {
t.Error(err)
}
}
}
func BenchmarkMaps_New(b *testing.B) {
mm := Maps{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
//noinspection GoUnhandledErrorResult
mm.New(fmt.Sprintf("map%d", i))
}
}
func testMapsNew(t *testing.T, mm Maps) {
if _, err := mm.New("new map"); err != nil {
t.Error(err)
}
}
func TestMaps_New(t *testing.T) {
for _, mm := range []Maps{emptyMaps, populatedMaps} {
testMapsNew(t, mm)
}
}