-
Notifications
You must be signed in to change notification settings - Fork 1
/
zero_test.go
58 lines (48 loc) · 972 Bytes
/
zero_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
package o_test
import (
"testing"
"github.com/antifuchs/o"
"github.com/stretchr/testify/assert"
)
func newRing() o.Ring {
return o.NewRing(0)
}
func TestZeroMeaningless(t *testing.T) {
r := newRing()
for i := 0; i < 2; i++ {
assert.False(t, r.Empty())
assert.True(t, r.Full())
assert.Equal(t, uint(0), r.Size())
assert.Equal(t, uint(0), r.Capacity())
r.Consume()
}
}
func TestZeroPush(t *testing.T) {
r := newRing()
var i uint
n, err := r.Push()
assert.Equal(t, o.ErrFull, err)
assert.Equal(t, i, n)
}
func TestZeroShift(t *testing.T) {
r := newRing()
_, err := r.Shift()
assert.Error(t, err)
var i uint
n, err := r.Push()
assert.Equal(t, o.ErrFull, err)
assert.Equal(t, uint(0), n)
i, err = r.Shift()
assert.Equal(t, o.ErrEmpty, err)
assert.Equal(t, uint(0), i)
}
func BenchmarkZeroRing(b *testing.B) {
r := newRing()
var i uint
for ; i < 1<<uint(b.N); i++ {
r.Push()
}
for i = 0; i < 1<<uint(b.N); i++ {
r.Shift()
}
}