mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +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:
1 parent
dc47b9ce98
commit
f1d7154179
2 files changed
+53
-20
No files matched your search
+26
-1
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user