From eff2f2244025f912642943a507da8e96c053a398 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sun, 15 May 2022 18:28:40 +0800 Subject: [PATCH] test: add unit test for MinBy function --- mathutil/mathutil_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mathutil/mathutil_test.go b/mathutil/mathutil_test.go index 3cc4698..3d93bf4 100644 --- a/mathutil/mathutil_test.go +++ b/mathutil/mathutil_test.go @@ -115,3 +115,22 @@ func TestMin(t *testing.T) { assert.Equal(Min(1, 2, 3), 1) assert.Equal(Min(1.2, 1.4, 1.1, 1.4), 1.1) } + +func TestMinBy(t *testing.T) { + assert := internal.NewAssert(t, "TestMinBy") + + res1 := MaxBy([]string{"a", "ab", "abc"}, func(v1, v2 string) bool { + return len(v1) < len(v2) + }) + assert.Equal("a", res1) + + res2 := MaxBy([]string{"ab", "ac", "abc"}, func(v1, v2 string) bool { + return len(v1) < len(v2) + }) + assert.Equal("ab", res2) + + res3 := MaxBy([]string{}, func(v1, v2 string) bool { + return len(v1) > len(v2) + }) + assert.Equal("", res3) +} \ No newline at end of file