feature: two evaluate operate func addtion in package stream (#3129)
Co-authored-by: Riven <Riven.chen@hairobotics.com>
This commit is contained in:
@@ -503,6 +503,83 @@ func TestStream_Concat(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestStream_Max(t *testing.T) {
|
||||
runCheckedTest(t, func(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
elements []any
|
||||
max any
|
||||
}{
|
||||
{
|
||||
name: "no elements with nil",
|
||||
},
|
||||
{
|
||||
name: "no elements",
|
||||
elements: []any{},
|
||||
max: nil,
|
||||
},
|
||||
{
|
||||
name: "1 element",
|
||||
elements: []any{1},
|
||||
max: 1,
|
||||
},
|
||||
{
|
||||
name: "multiple elements",
|
||||
elements: []any{1, 2, 9, 5, 8},
|
||||
max: 9,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
val := Just(test.elements...).Max(func(a, b any) bool {
|
||||
return a.(int) < b.(int)
|
||||
})
|
||||
assetEqual(t, test.max, val)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestStream_Min(t *testing.T) {
|
||||
runCheckedTest(t, func(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
elements []any
|
||||
min any
|
||||
}{
|
||||
{
|
||||
name: "no elements with nil",
|
||||
min: nil,
|
||||
},
|
||||
{
|
||||
name: "no elements",
|
||||
elements: []any{},
|
||||
min: nil,
|
||||
},
|
||||
{
|
||||
name: "1 element",
|
||||
elements: []any{1},
|
||||
min: 1,
|
||||
},
|
||||
{
|
||||
name: "multiple elements",
|
||||
elements: []any{-1, 1, 2, 9, 5, 8},
|
||||
min: -1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
val := Just(test.elements...).Min(func(a, b any) bool {
|
||||
return a.(int) < b.(int)
|
||||
})
|
||||
assetEqual(t, test.min, val)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkParallelMapReduce(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user