-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcomparable_test.go
103 lines (95 loc) · 2.04 KB
/
comparable_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
package fuego
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestComparableStream_Max(t *testing.T) {
tt := map[string]struct {
got func() interface{}
want interface{}
}{
"int": {
got: func() interface{} {
return CC(NewStreamFromSlice([]int{1, -2, 3, 21, 5, 8, 13}, 0).
Map(ToAny[int]), Int).
Max()
},
want: 21,
},
"uint": {
got: func() interface{} {
return CC(NewStreamFromSlice([]uint{1, 2, 3, 21, 5, 8, 13}, 0).
Map(ToAny[uint]), Uint).
Max()
},
want: uint(21),
},
"float32": {
got: func() interface{} {
return CC(NewStreamFromSlice([]float32{1.1, -2.2, 3.3, 21.21, 5.5, 8.8, 13.12}, 0).
Map(ToAny[float32]), Float32).
Max()
},
want: float32(21.21),
},
"string": {
got: func() interface{} {
return CC(NewStreamFromSlice([]string{"D", "K", "A", "Y", "M", "O"}, 0).
Map(ToAny[string]), String).
Max()
},
want: "Y",
},
}
for name, tc := range tt {
tc := tc
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.want, tc.got())
})
}
}
func TestComparableStream_Min(t *testing.T) {
tt := map[string]struct {
got func() interface{}
want interface{}
}{
"int": {
got: func() interface{} {
return CC(NewStreamFromSlice([]int{1, -2, 3, 21, 5, 8, 13}, 0).
Map(ToAny[int]), Int).
Min()
},
want: -2,
},
"uint": {
got: func() interface{} {
return CC(NewStreamFromSlice([]uint{2, 1, 3, 21, 5, 8, 13}, 0).
Map(ToAny[uint]), Uint).
Min()
},
want: uint(1),
},
"float32": {
got: func() interface{} {
return CC(NewStreamFromSlice([]float32{1.1, -2.2, 3.3, 21.21, 5.5, 8.8, 13.13}, 0).
Map(ToAny[float32]), Float32).
Min()
},
want: float32(-2.2),
},
"string": {
got: func() interface{} {
return CC(NewStreamFromSlice([]string{"D", "K", "A", "Y", "M", "O"}, 0).
Map(ToAny[string]), String).
Min()
},
want: "A",
},
}
for name, tc := range tt {
tc := tc
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.want, tc.got())
})
}
}