Feature/cover unit test (#81)

This commit is contained in:
libin
2024-07-31 19:51:01 +08:00
committed by GitHub
parent 0990bbce4d
commit a59af60d9a
60 changed files with 2571 additions and 2606 deletions

View File

@@ -3,12 +3,26 @@ package mathUtil
import "testing"
func TestRand(t *testing.T) {
minNum := 1
maxNum := 100
for i := 0; i < 1000; i++ {
num := Rand(minNum, maxNum)
if num < minNum || num > maxNum {
t.Errorf("randRange() returned %d, which is outside the range of [%d, %d]", num, minNum, maxNum)
}
testCases := []struct {
name string
minNum int
maxNum int
}{
{
name: "测试随机数在范围内",
minNum: 1,
maxNum: 100,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i := 0; i < 1000; i++ {
num := Rand(tc.minNum, tc.maxNum)
if num < tc.minNum || num > tc.maxNum {
t.Errorf("Rand(%d, %d) returned %d, which is outside the range of [%d, %d]", tc.minNum, tc.maxNum, num, tc.minNum, tc.maxNum)
}
}
})
}
}