Skip to content

Commit 8c0b57b

Browse files
committed
test(mathx,stringx): add missing edge case tests for CalcEntropy and HasEmpty
1 parent 8a2e09d commit 8c0b57b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

core/mathx/entropy_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ func TestCalcDiffEntropy(t *testing.T) {
2929
}
3030
assert.True(t, CalcEntropy(m) < .99)
3131
}
32+
33+
func TestCalcEntropySingleItem(t *testing.T) {
34+
m := map[any]int{
35+
"only": 42,
36+
}
37+
assert.Equal(t, float64(1), CalcEntropy(m))
38+
}

core/stringx/strings_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,40 @@ func TestContainsString(t *testing.T) {
2929
}
3030
}
3131

32+
func TestHasEmpty(t *testing.T) {
33+
cases := []struct {
34+
args []string
35+
expect bool
36+
}{
37+
{
38+
args: []string{"a", "b", "c"},
39+
expect: false,
40+
},
41+
{
42+
args: []string{"a", "", "c"},
43+
expect: true,
44+
},
45+
{
46+
args: []string{""},
47+
expect: true,
48+
},
49+
{
50+
args: []string{},
51+
expect: false,
52+
},
53+
{
54+
args: nil,
55+
expect: false,
56+
},
57+
}
58+
59+
for _, each := range cases {
60+
t.Run(path.Join(each.args...), func(t *testing.T) {
61+
assert.Equal(t, each.expect, HasEmpty(each.args...))
62+
})
63+
}
64+
}
65+
3266
func TestNotEmpty(t *testing.T) {
3367
cases := []struct {
3468
args []string

0 commit comments

Comments
 (0)