2547d7fb6a
Also move existing base62 encode/decode operations to their only points of use.
32 lines
489 B
Go
32 lines
489 B
Go
package base62
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestRandom(t *testing.T) {
|
|
strings := make(map[string]struct{})
|
|
|
|
for i := 0; i < 100000; i++ {
|
|
c, err := Random(16)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := strings[c]; ok {
|
|
t.Fatalf("Unexpected duplicate string: %s", c)
|
|
}
|
|
strings[c] = struct{}{}
|
|
|
|
}
|
|
|
|
for i := 0; i < 3000; i++ {
|
|
c, err := Random(i)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(c) != i {
|
|
t.Fatalf("Expected length %d, got: %d", i, len(c))
|
|
}
|
|
}
|
|
}
|