-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprims_test.go
83 lines (74 loc) · 1.43 KB
/
prims_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package primitive
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUInt64GetPut(t *testing.T) {
assert := assert.New(t)
tests := []uint64{
0, 1, ^uint64(1),
13 << 30,
13 << 10,
0xfc<<30 | 0xb<<20 | 0xa<<10 | 0x1,
}
for _, tt := range tests {
p := make([]byte, 8)
UInt64Put(p, tt)
assert.Equal(tt, UInt64Get(p))
}
for _, tt := range tests {
p := make([]byte, 10)
UInt64Put(p, tt)
assert.Equal(tt, UInt64Get(p), "with larger buffer")
}
}
func TestUInt32GetPut(t *testing.T) {
assert := assert.New(t)
tests := []uint32{
0, 1, ^uint32(1),
13 << 15,
13 << 5,
0xfc<<15 | 0xb<<10 | 0xa<<5 | 0x1,
}
for _, tt := range tests {
p := make([]byte, 4)
UInt32Put(p, tt)
assert.Equal(tt, UInt32Get(p))
}
for _, tt := range tests {
p := make([]byte, 10)
UInt32Put(p, tt)
assert.Equal(tt, UInt32Get(p), "with larger buffer")
}
}
func TestUInt64ToString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
Num uint64
Str string
}{
{0, "0"},
{2, "2"},
{1024, "1024"},
}
for _, tt := range tests {
assert.Equal(tt.Str, UInt64ToString(tt.Num))
}
}
func TestRandomDoesNotPanic(t *testing.T) {
// not much we can test here
RandomUint64()
RandomUint64()
}
func TestLinearizeDoesNothing(t *testing.T) {
// not much we can test here
Linearize()
}
func TestWaitTimeout(t *testing.T) {
var m sync.Mutex
c := sync.NewCond(&m)
m.Lock()
WaitTimeout(c, 10)
m.Unlock()
}