test(mathx,stringx): add missing edge case tests for CalcEntropy and … (#5471)

This commit is contained in:
Amshith Nair
2026-03-22 08:54:02 +05:30
committed by GitHub
parent 85d770d340
commit c12c82b2f6
2 changed files with 41 additions and 0 deletions

View File

@@ -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))
}

View File

@@ -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