mirror of
https://github.com/samber/lo.git
synced 2025-10-05 07:56:51 +08:00
oops
This commit is contained in:
@@ -130,6 +130,7 @@ func PartitionBy[T any, K comparable](collection []T, iteratee func (x T) K) [][
|
|||||||
result[resultIndex] = append(result[resultIndex], _item)
|
result[resultIndex] = append(result[resultIndex], _item)
|
||||||
|
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
wg.Done()
|
||||||
}(item)
|
}(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
package parallel
|
package parallel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -41,6 +42,13 @@ func TestGroupBy(t *testing.T) {
|
|||||||
return i % 3
|
return i % 3
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// order
|
||||||
|
for x := range result1 {
|
||||||
|
sort.Slice(result1[x], func(i, j int) bool {
|
||||||
|
return result1[x][i] < result1[x][j]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
is.EqualValues(len(result1), 3)
|
is.EqualValues(len(result1), 3)
|
||||||
is.EqualValues(result1, map[int][]int{
|
is.EqualValues(result1, map[int][]int{
|
||||||
0: []int{0, 3},
|
0: []int{0, 3},
|
||||||
@@ -64,6 +72,16 @@ func TestPartitionBy(t *testing.T) {
|
|||||||
result1 := PartitionBy[int, string]([]int{-2, -1, 0, 1, 2, 3, 4, 5}, oddEven)
|
result1 := PartitionBy[int, string]([]int{-2, -1, 0, 1, 2, 3, 4, 5}, oddEven)
|
||||||
result2 := PartitionBy[int, string]([]int{}, oddEven)
|
result2 := PartitionBy[int, string]([]int{}, oddEven)
|
||||||
|
|
||||||
is.Equal(result1, [][]int{{-2, -1}, {0, 2, 4}, {1, 3, 5}})
|
// order
|
||||||
|
sort.Slice(result1, func(i, j int) bool {
|
||||||
|
return result1[i][0] < result1[j][0]
|
||||||
|
})
|
||||||
|
for x := range result1 {
|
||||||
|
sort.Slice(result1[x], func(i, j int) bool {
|
||||||
|
return result1[x][i] < result1[x][j]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
is.ElementsMatch(result1, [][]int{{-2, -1}, {0, 2, 4}, {1, 3, 5}})
|
||||||
is.Equal(result2, [][]int{})
|
is.Equal(result2, [][]int{})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user