mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-04 22:52:40 +08:00
Feature/cover unit test (#81)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user