forked from name5566/leaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
92 lines (72 loc) · 1.09 KB
/
example_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
86
87
88
89
90
91
92
package util_test
import (
"fmt"
"github.com/name5566/leaf/util"
)
func ExampleMap() {
m := new(util.Map)
fmt.Println(m.Get("key"))
m.Set("key", "value")
fmt.Println(m.Get("key"))
m.Del("key")
fmt.Println(m.Get("key"))
m.Set(1, "1")
m.Set(2, 2)
m.Set("3", 3)
fmt.Println(m.Len())
// Output:
// <nil>
// value
// <nil>
// 3
}
func ExampleRandGroup() {
i := util.RandGroup(0, 0, 50, 50)
switch i {
case 2, 3:
fmt.Println("ok")
}
// Output:
// ok
}
func ExampleRandInterval() {
v := util.RandInterval(-1, 1)
switch v {
case -1, 0, 1:
fmt.Println("ok")
}
// Output:
// ok
}
func ExampleRandIntervalN() {
r := util.RandIntervalN(-1, 0, 2)
if r[0] == -1 && r[1] == 0 ||
r[0] == 0 && r[1] == -1 {
fmt.Println("ok")
}
// Output:
// ok
}
func ExampleDeepCopy() {
src := []int{1, 2, 3}
var dst []int
util.DeepCopy(&dst, &src)
for _, v := range dst {
fmt.Println(v)
}
// Output:
// 1
// 2
// 3
}
func ExampleDeepClone() {
src := []int{1, 2, 3}
dst := util.DeepClone(src).([]int)
for _, v := range dst {
fmt.Println(v)
}
// Output:
// 1
// 2
// 3
}