-
Notifications
You must be signed in to change notification settings - Fork 10
/
uuid_test.go
69 lines (52 loc) · 996 Bytes
/
uuid_test.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package util
import (
"testing"
"golang.org/x/exp/rand"
"gotest.tools/assert"
)
func TestUUID(t *testing.T) {
assert.Assert(t, PoorManUUID(true)%2 == 1)
assert.Assert(t, PoorManUUID(false)%2 == 0)
assert.Assert(t, FastRandN(1) == 0)
for i := 2; i < 100; i++ {
assert.Assert(t, FastRandN(uint32(i)) < uint32(i))
}
// test empty interface
var i interface{}
type test struct {
a int
b string
}
var s test
s.a = 1
s.b = "1"
i = s
s.a = 2
s.b = "2"
assert.Assert(t, i.(test).a == 1)
var i2 interface{}
i2 = i
i = s
s.a = 3
s.b = "3"
assert.Assert(t, i.(test).a == 2 && i2.(test).a == 1)
// // this will error
// i2.(test).a = 3
// test slice
{
encID := make([]byte, 0, 10)
_ = append(encID, 'a')
assert.Assert(t, len(encID) == 0 && cap(encID) == 10)
}
}
func BenchmarkFastRand(b *testing.B) {
for i := 0; i < b.N; i++ {
FastRand()
}
}
func BenchmarkPCG(b *testing.B) {
r := rand.PCGSource{}
for i := 0; i < b.N; i++ {
r.Uint64()
}
}