From 298219aee78e0b82915f144d396f977cb56066fd Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sun, 15 May 2022 18:21:01 +0800 Subject: [PATCH] test: add unit test for MaxBy function --- mathutil/mathutil_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mathutil/mathutil_test.go b/mathutil/mathutil_test.go index b324ad6..3cc4698 100644 --- a/mathutil/mathutil_test.go +++ b/mathutil/mathutil_test.go @@ -89,6 +89,25 @@ func TestMax(t *testing.T) { assert.Equal(Max(1.2, 1.4, 1.1, 1.4), 1.4) } +func TestMaxBy(t *testing.T) { + assert := internal.NewAssert(t, "MaxBy") + + res1 := MaxBy([]string{"a", "ab", "abc"}, func(v1, v2 string) bool { + return len(v1) > len(v2) + }) + assert.Equal("abc", res1) + + res2 := MaxBy([]string{"abd", "abc", "ab"}, func(v1, v2 string) bool { + return len(v1) > len(v2) + }) + assert.Equal("abd", res2) + + res3 := MaxBy([]string{}, func(v1, v2 string) bool { + return len(v1) > len(v2) + }) + assert.Equal("", res3) +} + func TestMin(t *testing.T) { assert := internal.NewAssert(t, "TestMin")