From aa5c8c585ca794aa94747d16d39754c927903cf6 Mon Sep 17 00:00:00 2001 From: guanren Date: Fri, 18 Oct 2024 13:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0test=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- random/random.go | 1 + random/random_test.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/random/random.go b/random/random.go index bceca50..9d7dc5f 100644 --- a/random/random.go +++ b/random/random.go @@ -329,6 +329,7 @@ func UUIdV4() (string, error) { } // RandNumLen 生成一个长度为len的随机数 +// Play: https://go.dev/play/p/jpIalcD5rMo func RandNumLen(len int) int { m := int(math.Pow10(len) - 1) i := int(math.Pow10(len - 1)) diff --git a/random/random_test.go b/random/random_test.go index f7df09d..9f0f5e0 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -3,6 +3,7 @@ package random import ( "reflect" "regexp" + "strconv" "testing" "github.com/duke-git/lancet/v2/internal" @@ -361,3 +362,9 @@ func TestRandBoolSlice(t *testing.T) { } }) } +func TestRandNumLen(t *testing.T) { + t.Parallel() + randi := RandNumLen(6) + assert := internal.NewAssert(t, "TestRandNumLen") + assert.Equal(6, len(strconv.Itoa(randi))) +}