diff --git a/README.md b/README.md index 29fa3d3..4519d38 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@
![Go version](https://img.shields.io/badge/go-%3E%3D1.16-9cf) -[![Release](https://img.shields.io/badge/release-1.1.8-green.svg)](https://github.com/duke-git/lancet/releases) +[![Release](https://img.shields.io/badge/release-1.1.9-green.svg)](https://github.com/duke-git/lancet/releases) [![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet) [![codecov](https://codecov.io/gh/duke-git/lancet/branch/main/graph/badge.svg?token=FC48T1F078)](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 @@
![Go version](https://img.shields.io/badge/go-%3E%3D1.16-9cf) -[![Release](https://img.shields.io/badge/release-1.1.8-green.svg)](https://github.com/duke-git/lancet/releases) +[![Release](https://img.shields.io/badge/release-1.1.9-green.svg)](https://github.com/duke-git/lancet/releases) [![GoDoc](https://godoc.org/github.com//duke-git/lancet?status.svg)](https://pkg.go.dev/github.com/duke-git/lancet) [![Go Report Card](https://goreportcard.com/badge/github.com/duke-git/lancet)](https://goreportcard.com/report/github.com/duke-git/lancet) [![codecov](https://codecov.io/gh/duke-git/lancet/branch/main/graph/badge.svg?token=FC48T1F078)](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))