Skip to content

Commit

Permalink
pref: 新增测试用例,验证NanoID的随机安全性
Browse files Browse the repository at this point in the history
  • Loading branch information
ccpwcn committed Dec 26, 2024
1 parent 893bfeb commit bc28ae9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions nanoid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ func TestNormalNanoID(t *testing.T) {
}
}

func TestMustNanoID_CountLetter(t *testing.T) {
var m = make(map[byte]int)
for i := 0; i < 1000_0000; i++ {
id := MustNanoId()
for j := 0; j < len(id); j++ {
m[id[j]]++
}
}
for k, v := range m {
t.Logf("%q: %d\n", k, v)
}
}

func TestNormalNanoID_CheckDuplicate(t *testing.T) {
const count = 100_0000
ids := make(map[string]bool, count)
Expand Down

0 comments on commit bc28ae9

Please sign in to comment.