move ShuffleStrings to pkg/proxy
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>
This commit is contained in:
@@ -10,7 +10,6 @@ go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["slice.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/util/slice",
|
||||
deps = ["//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
@@ -19,8 +19,6 @@ package slice
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
utilrand "k8s.io/apimachinery/pkg/util/rand"
|
||||
)
|
||||
|
||||
// CopyStrings copies the contents of the specified string slice
|
||||
@@ -41,20 +39,6 @@ func SortStrings(s []string) []string {
|
||||
return s
|
||||
}
|
||||
|
||||
// ShuffleStrings copies strings from the specified slice into a copy in random
|
||||
// order. It returns a new slice.
|
||||
func ShuffleStrings(s []string) []string {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
shuffled := make([]string, len(s))
|
||||
perm := utilrand.Perm(len(s))
|
||||
for i, j := range perm {
|
||||
shuffled[j] = s[i]
|
||||
}
|
||||
return shuffled
|
||||
}
|
||||
|
||||
// ContainsString checks if a given slice of strings contains the provided string.
|
||||
// If a modifier func is provided, it is called with the slice item before the comparation.
|
||||
func ContainsString(slice []string, s string, modifier func(s string) string) bool {
|
||||
|
@@ -63,33 +63,6 @@ func TestSortStrings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestShuffleStrings(t *testing.T) {
|
||||
var src []string
|
||||
dest := ShuffleStrings(src)
|
||||
|
||||
if dest != nil {
|
||||
t.Errorf("ShuffleStrings for a nil slice got a non-nil slice")
|
||||
}
|
||||
|
||||
src = []string{"a", "b", "c", "d", "e", "f"}
|
||||
dest = ShuffleStrings(src)
|
||||
|
||||
if len(src) != len(dest) {
|
||||
t.Errorf("Shuffled slice is wrong length, expected %v got %v", len(src), len(dest))
|
||||
}
|
||||
|
||||
m := make(map[string]bool, len(dest))
|
||||
for _, s := range dest {
|
||||
m[s] = true
|
||||
}
|
||||
|
||||
for _, k := range src {
|
||||
if _, exists := m[k]; !exists {
|
||||
t.Errorf("Element %v missing from shuffled slice", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContainsString(t *testing.T) {
|
||||
src := []string{"aa", "bb", "cc"}
|
||||
if !ContainsString(src, "bb", nil) {
|
||||
|
Reference in New Issue
Block a user