refactor: sort (#21)

Removed reverse func because it use to much cpu and add test cas for asc sort
This commit is contained in:
donutloop authored and GitHub committed 2022-01-11 19:24:36 +08:00
1 parent dc47b9ce98
commit f1d7154179
2 files changed
+53 -20

No files matched your search

+26 -1
View File
@@ -381,7 +381,7 @@ func TestDifference(t *testing.T) {
assert.Equal([]int{1, 2, 3}, Difference(s1, s2))
}
func TestSortByField(t *testing.T) {
func TestSortByFieldDesc(t *testing.T) {
assert := internal.NewAssert(t, "TestSortByField")
type student struct {
@@ -406,6 +406,31 @@ func TestSortByField(t *testing.T) {
assert.Equal(students, studentsOfSortByAge)
}
func TestSortByFieldAsc(t *testing.T) {
assert := internal.NewAssert(t, "TestSortByField")
type student struct {
name string
age int
}
students := []student{
{"a", 10},
{"b", 15},
{"c", 5},
{"d", 6},
}
studentsOfSortByAge := []student{
{"c", 5},
{"d", 6},
{"a", 10},
{"b", 15},
}
err := SortByField(students, "age")
assert.IsNil(err)
assert.Equal(students, studentsOfSortByAge)
}
func TestWithout(t *testing.T) {
assert := internal.NewAssert(t, "TestWithout")