-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueId_test.go
More file actions
42 lines (37 loc) · 856 Bytes
/
UniqueId_test.go
File metadata and controls
42 lines (37 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package u_test
import (
"fmt"
"testing"
"github.com/ssgo/u"
)
//func TestId(t *testing.T) {
// for _, nx := range []string{"99u", "UUU", "999u", "UUUU", "9999u", "UUUUU", "99999u", "UUUUUU"} {
// fmt.Println(nx, u.DecodeInt([]byte(nx)))
// }
// for i:=0; i<10; i++ {
// dd := u.ShortUniqueId()
// fmt.Println(dd, len(dd))
// }
//}
func TestUniqueId(t *testing.T) {
fmt.Println(u.MakeId(12))
uids := map[string]bool{}
for range 100000 {
uid := u.MakeId(12)
if uids[uid] || len(uid) != 12 {
t.Error("unique id repeated ", uid, len(uid))
}
uids[uid] = true
}
}
func TestShortUniqueId(t *testing.T) {
fmt.Println(u.MakeId(20), len(u.MakeId(20)))
uids := map[string]bool{}
for range 100000 {
uid := u.MakeId(20)
if uids[uid] || len(uid) != 20 {
t.Error("short unique id repeated ", uid, len(uid))
}
uids[uid] = true
}
}