forked from jianfengye/collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
int64_collection_test.go
73 lines (63 loc) · 1.26 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
package collection
import (
"errors"
"reflect"
"testing"
)
func TestInt64Collection(t *testing.T) {
arr := NewInt64Collection([]int64{1,2,3,4,5})
arr.DD()
max, err := arr.Max().ToInt64()
if err != nil {
t.Error(err)
}
if max != 5 {
t.Error(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.Error(errors.New("filter error"))
}
out, err := arr2.ToInt64s()
if err != nil || len(out) != 3{
t.Error("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.Error(err)
}
if !reflect.DeepEqual(b, []int64{1, 10, 2, 3}) {
t.Error("insert error")
}
}
{
a := NewInt64Collection([]int64{1,2,3})
b, err := a.Insert(0, int64(10)).ToInt64s()
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(b, []int64{10, 1, 2, 3}) {
t.Error("insert 0 error")
}
}
{
a := NewInt64Collection([]int64{1,2,3})
b, err := a.Insert(3, int64(10)).ToInt64s()
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(b, []int64{1, 2, 3, 10}) {
t.Error("insert length error")
}
}
}