-
Notifications
You must be signed in to change notification settings - Fork 1
/
aggregate_test.go
70 lines (57 loc) · 1.26 KB
/
aggregate_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
package flinx
import (
"testing"
"gotest.tools/v3/assert"
)
import "strings"
func Test_Aggregate(t *testing.T) {
First(Select(func(i int) int {
return i * 2
})(Where(func(i int) bool {
return i%2 == 0
})(Range(1, 10))))
tests := []struct {
input []string
want interface{}
}{
{[]string{"apple", "mango", "orange", "passionfruit", "grape"}, "passionfruit"},
{[]string{}, ""},
}
aggr := Aggregate(func(r, i string) string {
if len(r) > len(i) {
return r
}
return i
})
for _, test := range tests {
r := aggr(FromSlice(test.input))
assert.Equal(t, r, test.want)
}
}
func TestAggregateWithSeed(t *testing.T) {
input := []string{"apple", "mango", "orange", "banana", "grape"}
want := "passionfruit"
aggr := AggregateWithSeed(want, func(r, i string) string {
if len(r) > len(i) {
return r
}
return i
})
r := aggr(FromSlice(input))
assert.Equal(t, r, want)
}
func TestAggregateWithSeedBy(t *testing.T) {
input := []string{"apple", "mango", "orange", "passionfruit", "grape"}
want := "PASSIONFRUIT"
aggr := AggregateWithSeedBy("banana", func(r, i string) string {
if len(r) > len(i) {
return r
}
return i
},
func(r string) string {
return strings.ToUpper(r)
})
r := aggr(FromSlice(input))
assert.Equal(t, r, want)
}