publish lancet

This commit is contained in:
dudaodong committed 2021-11-28 21:28:23 +08:00
1 parent 37edb0fc8f
commit 3254591ab9
38 files changed
+5163

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package random
import (
"fmt"
"github.com/duke-git/lancet/utils"
"reflect"
"regexp"
"testing"
)
func TestRandString(t *testing.T) {
randStr := RandString(6)
fmt.Println(randStr)
pattern := `^[a-zA-Z]+$`
reg := regexp.MustCompile(pattern)
if len(randStr) != 6 || !reg.MatchString(randStr) {
utils.LogFailedTestInfo(t, "RandString", "RandString(6)", "RandString(6) should be 6 letters ", randStr)
t.FailNow()
}
}
func TestRandInt(t *testing.T) {
randInt := RandInt(1, 10)
if randInt < 1 || randInt >= 10 {
utils.LogFailedTestInfo(t, "RandInt", "RandInt(1, 10)", "RandInt(1, 10) should between [1, 10) ", randInt)
t.FailNow()
}
}
func TestRandBytes(t *testing.T) {
randBytes := RandBytes(4)
if len(randBytes) != 4 {
utils.LogFailedTestInfo(t, "RandBytes", "RandBytes(4)", "RandBytes(4) should return 4 element of []bytes", randBytes)
t.FailNow()
}
v := reflect.ValueOf(randBytes)
et := v.Type().Elem()
if v.Kind() != reflect.Slice || et.Kind() != reflect.Uint8 {
utils.LogFailedTestInfo(t, "RandBytes", "RandBytes(4)", "RandBytes(4) should return 4 element of []bytes", randBytes)
t.FailNow()
}
}