-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsl_test.go
130 lines (107 loc) · 2.28 KB
/
dsl_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package hy_go_function
import (
"fmt"
"hy-go-function/internal"
"strconv"
"testing"
)
func Test_Stream(t *testing.T) {
array := []string{
"1", "2", "3",
}
result := Of(array).Map(func(i string) int {
atoi, err := strconv.Atoi(i)
if err != nil {
return 0
}
return atoi
}).Filter(func(i int) bool {
if i == 1 {
return false
}
return true
}).Map(func(i int) int {
return i + 5
}).Execute()
println(fmt.Sprintf("result : %v", result))
}
func Test_filterEmpty(t *testing.T) {
array := []string{
}
result := internal.DoFilter(array, func(i string) bool {
if i == "1" {
return false
}
return true
})
println(fmt.Sprintf("result : %v", result))
}
func Test_filter(t *testing.T) {
array := []string{
"1", "2", "3",
}
result := internal.DoFilter(array, func(i string) bool {
if i == "1" {
return false
}
return true
})
println(fmt.Sprintf("result : %v", result))
result2 := internal.DoFilter(1, func(i int) bool {
if i != 1 {
return false
}
return true
})
println(fmt.Sprintf("result : %v", result2))
}
func Test_mapEmpty(t *testing.T) {
array := []string{
}
result := internal.DoMap(array, func(i string) int {
if i == "1" {
return 1
}
return 2
})
println(fmt.Sprintf("result : %v", result))
}
func Test_map(t *testing.T) {
array := []string{
"1", "2", "3",
}
result := internal.DoMap(array, func(i string) int {
if i == "1" {
return 1
}
return 2
})
println(fmt.Sprintf("result : %v", result))
result2 := internal.DoMap(1, func(i int) int { return i + 1 })
println(fmt.Sprintf("result2 : %v", result2))
}
func Test_flatmap(t *testing.T) {
array := [][]string{
{"1", "2", "3"},
{"1", "2", "3"},
}
result := internal.DoFlatMap(array, func(i []string) []string {
return i
})
println(fmt.Sprintf("result : %v", result))
result2 := internal.DoMap(1, func(i int) int { return i + 1 })
println(fmt.Sprintf("result2 : %v", result2))
}
func Test_reduce(t *testing.T) {
array := []int{
1, 2, 3,
}
var result = internal.DoReduce(array, func(x int, y int) int {
return x + y
}, 0).(int)
println(fmt.Sprintf("result : %v", result))
var result2 = internal.DoReduce(array, func(x string, y int) string {
return x + "," + strconv.Itoa(y)
}, "").(string)
println(fmt.Sprintf("result2 : %v", result2))
}