-9cf)
-[](https://github.com/duke-git/lancet/releases)
+[](https://github.com/duke-git/lancet/releases)
[](https://pkg.go.dev/github.com/duke-git/lancet)
[](https://goreportcard.com/report/github.com/duke-git/lancet)
[](https://codecov.io/gh/duke-git/lancet)
diff --git a/README_zh-CN.md b/README_zh-CN.md
index 49a8914..754870e 100644
--- a/README_zh-CN.md
+++ b/README_zh-CN.md
@@ -6,7 +6,7 @@

-[](https://github.com/duke-git/lancet/releases)
+[](https://github.com/duke-git/lancet/releases)
[](https://pkg.go.dev/github.com/duke-git/lancet)
[](https://goreportcard.com/report/github.com/duke-git/lancet)
[](https://codecov.io/gh/duke-git/lancet)
diff --git a/internal/assert.go b/internal/assert.go
index 80d42f5..3e817d8 100644
--- a/internal/assert.go
+++ b/internal/assert.go
@@ -18,7 +18,7 @@ const (
compareGreater
)
-// Assert is a simple implementation of assertion, only for internal useage
+// Assert is a simple implementation of assertion, only for internal usage
type Assert struct {
T *testing.T
CaseName string
@@ -154,9 +154,8 @@ func compare(x, y interface{}) int {
default:
if reflect.DeepEqual(x, y) {
return compareEqual
- } else {
- return compareNotEqual
}
+ return compareNotEqual
}
return compareNotEqual
diff --git a/slice/slice_test.go b/slice/slice_test.go
index 20a1e0f..3e60fef 100644
--- a/slice/slice_test.go
+++ b/slice/slice_test.go
@@ -381,7 +381,7 @@ func TestDifference(t *testing.T) {
assert.Equal([]int{1, 2, 3}, Difference(s1, s2))
}
-func TestSortByField(t *testing.T) {
+func TestSortByFielDesc(t *testing.T) {
assert := internal.NewAssert(t, "TestWithout")
type student struct {
@@ -407,6 +407,32 @@ 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")
assert.Equal([]int{3, 4, 5}, Without([]int{1, 2, 3, 4, 5}, 1, 2))