split util/slice

This commit is contained in:
ymqytw
2017-06-29 16:07:31 -07:00
parent 5eccc7ae80
commit 8dac9639e4
10 changed files with 103 additions and 23 deletions

View File

@@ -68,14 +68,3 @@ func ContainsString(slice []string, s string, modifier func(s string) string) bo
}
return false
}
// Int64Slice attaches the methods of Interface to []int64,
// sorting in increasing order.
type Int64Slice []int64
func (p Int64Slice) Len() int { return len(p) }
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// Sorts []int64 in increasing order
func SortInts64(a []int64) { sort.Sort(Int64Slice(a)) }

View File

@@ -89,12 +89,3 @@ func TestShuffleStrings(t *testing.T) {
}
}
}
func TestSortInts64(t *testing.T) {
src := []int64{10, 1, 2, 3, 4, 5, 6}
expected := []int64{1, 2, 3, 4, 5, 6, 10}
SortInts64(src)
if !reflect.DeepEqual(src, expected) {
t.Errorf("func Ints64 didnt sort correctly, %v !- %v", src, expected)
}
}