Skip to content

Commit

Permalink
fix: add random_string unit-test (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool authored Sep 21, 2023
1 parent 5423ebf commit 29e74ae
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 @@ -2547,3 +2547,33 @@ func TestWithInterfaceStructWithIgnoreFalse(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 29e74ae

Please sign in to comment.