From c12c82b2f6efe51d87b2386c0cb0deae0ba1a208 Mon Sep 17 00:00:00 2001 From: Amshith Nair Date: Sun, 22 Mar 2026 08:54:02 +0530 Subject: [PATCH] =?UTF-8?q?test(mathx,stringx):=20add=20missing=20edge=20c?= =?UTF-8?q?ase=20tests=20for=20CalcEntropy=20and=20=E2=80=A6=20(#5471)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/mathx/entropy_test.go | 7 +++++++ core/stringx/strings_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/core/mathx/entropy_test.go b/core/mathx/entropy_test.go index 03db018d1..1f477acac 100644 --- a/core/mathx/entropy_test.go +++ b/core/mathx/entropy_test.go @@ -29,3 +29,10 @@ func TestCalcDiffEntropy(t *testing.T) { } assert.True(t, CalcEntropy(m) < .99) } + +func TestCalcEntropySingleItem(t *testing.T) { + m := map[any]int{ + "only": 42, + } + assert.Equal(t, float64(1), CalcEntropy(m)) +} diff --git a/core/stringx/strings_test.go b/core/stringx/strings_test.go index b4681fe5c..0adcaf3ab 100644 --- a/core/stringx/strings_test.go +++ b/core/stringx/strings_test.go @@ -29,6 +29,40 @@ func TestContainsString(t *testing.T) { } } +func TestHasEmpty(t *testing.T) { + cases := []struct { + args []string + expect bool + }{ + { + args: []string{"a", "b", "c"}, + expect: false, + }, + { + args: []string{"a", "", "c"}, + expect: true, + }, + { + args: []string{""}, + expect: true, + }, + { + args: []string{}, + expect: false, + }, + { + args: nil, + expect: false, + }, + } + + for _, each := range cases { + t.Run(path.Join(each.args...), func(t *testing.T) { + assert.Equal(t, each.expect, HasEmpty(each.args...)) + }) + } +} + func TestNotEmpty(t *testing.T) { cases := []struct { args []string