-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
92 lines (75 loc) · 1.56 KB
/
example_test.go
File metadata and controls
92 lines (75 loc) · 1.56 KB
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 slice_test
import (
"fmt"
"github.com/sina-devel/slice"
)
func ExampleEqual() {
s1 := []int8{20, 3, 4}
s2 := []int8{20, 3, 4}
fmt.Println(slice.Equal(s1, s2))
//Output:
// true
}
func ExampleEqualFunc() {
s1 := []int8{20, 2}
s2 := []int16{20, 2}
fmt.Println(slice.EqualFunc(s1, s2, func(a int8, b int16) bool {
return int16(a) == b
}))
//Output:
// true
}
func ExampleIndex() {
s := []int{10, 20, 40}
fmt.Println("20 exists at index", slice.Index(s, 20))
//Output:
// 20 exists at index 1
}
func ExampleIndexFunc() {
type Point struct {
x, y int16
}
points := []Point{{10, 2}, {4, 4}}
fmt.Println("point(10, _) exists at index", slice.IndexFunc(points, func(p Point) bool {
return p.x == 10
}))
//Output:
// point(10, _) exists at index 0
}
func ExampleContains() {
animals := []string{"zebra", "lion", "gopher"}
if slice.Contains(animals, "gopher") {
fmt.Println("ʕ◔ϖ◔ʔ")
}
//Output:
// ʕ◔ϖ◔ʔ
}
func ExampleClone() {
numbers := []float64{1.0, 10.2, 39.2}
cloned := slice.Clone(numbers)
cloned[0] = 23.3
fmt.Println(numbers, cloned)
//Output:
// [1 10.2 39.2] [23.3 10.2 39.2]
}
func ExampleSort() {
s := []rune{'🥚', '🐔'}
slice.Sort(s, func(a, b rune) bool { return a < b })
fmt.Printf("%q", s)
//Output:
// ['🐔' '🥚']
}
func ExampleInsert() {
s := []rune{'p', 'h', 'e', 'r'}
s = slice.Insert(s, 0, 'G', 'o')
fmt.Println(string(s))
//Output:
// Gopher
}
func ExampleDelete() {
s := []rune{'H', 'e', 'l', 'l', 'o', 'o', 'o'}
s = slice.Delete(s, 5, 7)
fmt.Println(string(s))
//Output:
// Hello
}