forked from LeoYoung-code/utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapreduce_test.go
More file actions
85 lines (75 loc) · 1.83 KB
/
mapreduce_test.go
File metadata and controls
85 lines (75 loc) · 1.83 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
package utils
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMap(t *testing.T) {
words := []string{"1", "2", "3", "4"}
quoted := Map(words, func(s string) int64 {
i, _ := strconv.ParseInt(s, 10, 64)
return i
})
t.Log(quoted)
}
func TestReduce(t *testing.T) {
numbers := []int{4, 9, 16, 25}
quoted := Reduce(numbers, 0, func(i, j int) int {
return i + j
})
t.Log(quoted)
}
func TestFilter(t *testing.T) {
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
dual := Filter(numbers, true, func(in int) bool {
return in%2 == 0
})
t.Log(dual)
}
func TestGetStructName(t *testing.T) {
type bar struct{}
foo := bar{}
t.Log(GetStructName(foo))
}
func TestSet(t *testing.T) {
numbers := []int{1, 2, 3, 3, 1}
set := Set(numbers)
assert.Equal(t, []int{1, 2, 3}, set)
s := []string{"1", "1", "3", "2", "3"}
ss := Set(s)
assert.Equal(t, []string{"1", "3", "2"}, ss)
}
func Test_SliceIntersect_string(t *testing.T) {
tests := []struct {
name string
slice1 []string
slice2 []string
want []string
}{
{"string1", []string{"1", "2", "3", "1"}, []string{"2", "10"}, []string{"2"}},
{"string2", []string{"1", "2", "3"}, []string{"5", "10"}, []string{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := SliceIntersect(tt.slice1, tt.slice2)
assert.Equalf(t, tt.want, w, "hasIntersectString(%v, %v)", tt.slice1, tt.slice2)
})
}
}
func Test_SliceIntersect_int(t *testing.T) {
tests := []struct {
name string
slice1 []int
slice2 []int
want []int
}{
{"int1", []int{1, 2, 3, 1}, []int{2, 10}, []int{2}},
{"int2", []int{1, 2, 3}, []int{5, 10}, []int{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := SliceIntersect(tt.slice1, tt.slice2)
assert.Equalf(t, tt.want, w, "hasIntersectString(%v, %v)", tt.slice1, tt.slice2)
})
}
}