Skip to content

Commit

Permalink
fix: add random_string unit-test
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool committed Sep 19, 2023
1 parent f70bf73 commit 72d562c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2507,3 +2507,33 @@ func TestNonEmptyInterface(t *testing.T) {
t.FailNow()
}
}

func BenchmarkRandomString(b *testing.B) {
opt := options.DefaultOption()
for i := 0; i < b.N; i++ {
_, err := randomString(10, *opt)
if err != nil {
b.Error("Expected NoError, but Got Err:", err)
}
}
}

func TestRandomString(t *testing.T) {
var (
count = 1000
set = map[string]struct{}{}
opt = options.DefaultOption()
)

for i := 0; i < count; i++ {
str, err := randomString(20, *opt)
if err != nil {
t.Error("Expected NoError, but Got Err:", err)
}
set[str] = struct{}{}
}

if len(set) != count {
t.Error("random string in set is duplicate")
}
}

0 comments on commit 72d562c

Please sign in to comment.