forked from gree/futurama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seq_test.go
50 lines (46 loc) · 885 Bytes
/
seq_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
package futurama
import (
"github.com/golang/glog"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestSeq_increment(t *testing.T) {
var a Seq32
assert.Equal(t, a, Seq32(0))
for x := 0; x < 10; x++ {
go func() {
for i := 0; i < 10; i++ {
glog.Infoln(a.Next())
}
}()
}
time.Sleep(time.Second)
assert.Equal(t, a.Get(), int32(100))
}
func TestSeq_overflow(t *testing.T) {
var a = Seq32(SEQ_MASK_INT32 - 5)
assert.Equal(t, a, Seq32(SEQ_MASK_INT32-5))
for x := 0; x < 5; x++ {
glog.Infoln(a.Next())
}
for x := 0; x < 5; x++ {
v := a.Next()
glog.Infoln(v)
assert.Equal(t, v, int32(x))
}
}
func TestSeq_reset(t *testing.T) {
var a Seq32
for x := 1; x < 5; x++ {
v := a.Next()
glog.Infoln(v)
assert.Equal(t, v, int32(x))
}
a.Reset()
for x := 1; x < 5; x++ {
v := a.Next()
glog.Infoln(v)
assert.Equal(t, v, int32(x))
}
}