mirror of
https://github.com/portainer/portainer.git
synced 2026-06-23 07:00:14 +00:00
22 lines
505 B
Go
22 lines
505 B
Go
package slicesx_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/portainer/portainer/api/slicesx"
|
|
)
|
|
|
|
func TestGroupBy(t *testing.T) {
|
|
t.Parallel()
|
|
input := []string{"apple", "banana", "cherry", "date", "elderberry"}
|
|
f := func(a string) int {
|
|
return len(a)
|
|
}
|
|
expected := map[int][]string{5: {"apple"}, 6: {"banana", "cherry"}, 4: {"date"}, 10: {"elderberry"}}
|
|
result := slicesx.GroupBy(input, f)
|
|
if !reflect.DeepEqual(expected, result) {
|
|
t.Errorf("Expected %v, got %v", expected, result)
|
|
}
|
|
}
|