1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 08:42:29 +08:00

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
2022-01-11 12:24:36 +01:00
committed by GitHub
parent dc47b9ce98
commit f1d7154179
2 changed files with 53 additions and 20 deletions

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")