-
Notifications
You must be signed in to change notification settings - Fork 2
/
lmaps_test.go
71 lines (63 loc) · 1.26 KB
/
lmaps_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
package genh
import (
"encoding/json"
"strconv"
"testing"
)
func TestLMap(t *testing.T) {
lm := LMapOf(map[string]S{
"a": {1},
"b": {2},
"c": {3},
"d": {4},
})
j, err := json.Marshal(lm)
DieIf(t, err)
var lm0 LMap[string, S]
DieIf(t, json.Unmarshal(j, &lm0))
if !MapEqual(lm.Raw(), lm0.Raw()) {
t.Fatal("lm != lm0", lm.Raw(), lm0.Raw())
}
j, err = MarshalMsgpack(lm)
DieIf(t, err)
var lm1 LMap[string, S]
DieIf(t, UnmarshalMsgpack(j, &lm1))
if !MapEqual(lm.Raw(), lm1.Raw()) {
t.Fatal("lm != lm1", lm.Raw(), lm1.Raw())
}
}
func TestSLMap(t *testing.T) {
sm := NewSLMap[S](0)
for i := 0; i < 10000; i++ {
sm.Set(strconv.Itoa(i), S{i})
}
for _, m := range sm.ms {
if m.Len() < 250 {
t.Fatal("m.Len() < 250", m.Len())
}
}
if sm.Len() != 10000 {
t.Fatal("sm.Len() != 10000", sm.Len())
}
count := 0
sm.ForEach(func(k string, v S) bool {
count++
return true
})
if count != 10000 {
t.Fatal("count != 10000", count)
}
j, err := MarshalMsgpack(sm)
DieIf(t, err)
var sm2 SLMap[S]
DieIf(t, UnmarshalMsgpack(j, &sm2))
if sm2.Len() != 10000 {
t.Fatal("sm2.Len() != 10000", sm2.Len())
}
sm2.ForEach(func(k string, v S) bool {
if v.X != sm.Get(k).X {
t.Fatal("v.I != sm.Get(k).I", v.X, sm.Get(k).X)
}
return true
})
}