-
Notifications
You must be signed in to change notification settings - Fork 23
/
int64_collection_test.go
81 lines (70 loc) · 1.45 KB
/
int64_collection_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
package collection
import (
"reflect"
"testing"
"github.com/pkg/errors"
)
func TestInt64Collection(t *testing.T) {
arr := NewInt64Collection([]int64{1, 2, 3, 4, 5})
arr.DD()
max, err := arr.Max().ToInt64()
if err != nil {
t.Fatal(err)
}
if max != 5 {
t.Fatal(errors.New("max error"))
}
arr2 := arr.Filter(func(obj interface{}, index int) bool {
val := obj.(int64)
if val > 2 {
return true
}
return false
})
if arr2.Count() != 3 {
t.Fatal(errors.New("filter error"))
}
out, err := arr2.ToInt64s()
if err != nil || len(out) != 3 {
t.Fatal("ToInt64s error")
}
}
func TestInt64Collection_Insert(t *testing.T) {
{
a := NewInt64Collection([]int64{1, 2, 3})
b, err := a.Insert(1, int64(10)).ToInt64s()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(b, []int64{1, 10, 2, 3}) {
t.Fatal("insert error")
}
}
{
a := NewInt64Collection([]int64{1, 2, 3})
b, err := a.Insert(0, int64(10)).ToInt64s()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(b, []int64{10, 1, 2, 3}) {
t.Fatal("insert 0 error")
}
}
{
a := NewInt64Collection([]int64{1, 2, 3})
b, err := a.Insert(3, int64(10)).ToInt64s()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(b, []int64{1, 2, 3, 10}) {
t.Fatal("insert length error")
}
}
}
func TestInt64Collection_Remove(t *testing.T) {
int64Coll := NewInt64Collection([]int64{1, 2, 3})
r := int64Coll.Remove(0)
if r.Err() != nil {
t.Fatal(r.Err())
}
}