-
Notifications
You must be signed in to change notification settings - Fork 1
/
ring_properties_test.go
81 lines (69 loc) · 1.87 KB
/
ring_properties_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
package o_test
import (
"fmt"
"testing"
"github.com/antifuchs/o"
"github.com/leanovate/gopter"
"github.com/leanovate/gopter/gen"
"github.com/leanovate/gopter/prop"
)
func TestPropShiftPushes(t *testing.T) {
params := gopter.DefaultTestParameters()
params.MinSuccessfulTests = 1000
properties := gopter.NewProperties(params)
properties.Property("Read own writes", prop.ForAll(
func(ringSize, entries uint) bool {
ring := o.NewRing(ringSize)
for i := uint(0); i < entries; i++ {
pushed, _ := ring.Push()
shifted, _ := ring.Shift()
if pushed != shifted {
return false
}
}
return true
},
gen.UInt().WithLabel("ring size"),
gen.UIntRange(1, 257*90).WithLabel("number of entries made"),
))
properties.TestingRun(t)
}
func TestPropBounds(t *testing.T) {
params := gopter.DefaultTestParameters()
params.MinSuccessfulTests = 1000
properties := gopter.NewProperties(params)
properties.Property("Read own writes", prop.ForAll(
func(ringSize, entries uint) string {
ring := o.NewRing(ringSize)
wFirst, wSecond, err := ring.PushN(entries)
if entries > ringSize {
if err == nil {
return "should have errored"
}
return ""
}
if entries == 0 {
if !ring.Empty() {
return "should be empty"
}
return ""
}
if entries == ringSize && !ring.Full() {
return "should be full"
}
if entries < ringSize && ring.Full() {
return "should not be full"
}
first, second := ring.Consume()
if (wFirst.Start != first.Start && first.End != wFirst.End+1) ||
(!second.Empty() && wSecond.Start != second.Start && second.End != wSecond.End+1) {
return fmt.Sprintf("Expected same ranges, but\n%#v %#v\n%#v %#v",
wFirst, wSecond, first, second)
}
return ""
},
gen.UInt().WithLabel("ring size"),
gen.UIntRange(0, 257*90).WithLabel("number of entries made"),
))
properties.TestingRun(t)
}