-
Notifications
You must be signed in to change notification settings - Fork 23
/
pbuf_test.go
72 lines (56 loc) · 1.47 KB
/
pbuf_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
package rbuf
import (
"fmt"
"testing"
cv "github.com/glycerine/goconvey/convey"
)
func TestPointerReadWrite(t *testing.T) {
b := NewPointerRingBuf(5)
data := []interface{}{}
for i := 0; i < 10; i++ {
data = append(data, interface{}(i))
}
cv.Convey("PointerRingBuf::PushAndMaybeOverwriteOldestData() should auto advance", t, func() {
b.Reset()
n, err := b.PushAndMaybeOverwriteOldestData(data[:3])
cv.So(err, cv.ShouldEqual, nil)
cv.So(n, cv.ShouldEqual, 3)
cv.So(b.Readable, cv.ShouldEqual, 3)
n, err = b.PushAndMaybeOverwriteOldestData(data[3:5])
cv.So(n, cv.ShouldEqual, 2)
cv.So(b.Readable, cv.ShouldEqual, 5)
check := make([]interface{}, 5)
n, err = b.ReadPtrs(check)
cv.So(n, cv.ShouldEqual, 5)
cv.So(check, cv.ShouldResemble, data[:5])
n, err = b.PushAndMaybeOverwriteOldestData(data[5:10])
cv.So(err, cv.ShouldEqual, nil)
cv.So(n, cv.ShouldEqual, 5)
n, err = b.ReadWithoutAdvance(check)
cv.So(n, cv.ShouldEqual, 5)
cv.So(check, cv.ShouldResemble, data[5:10])
// check TwoConfig
q, r := b.TwoContig()
//p("len q = %v", len(q))
//p("len r = %v", len(r))
found := make([]bool, 10)
for _, iface := range q {
q0 := iface.(int)
found[q0] = true
}
for _, iface := range r {
r0 := iface.(int)
found[r0] = true
}
totTrue := 0
for i := range found {
if found[i] {
totTrue++
}
}
cv.So(totTrue, cv.ShouldEqual, 5)
})
}
func p(format string, a ...interface{}) {
fmt.Printf("\n"+format+"\n", a...)
}