forked from leanovate/gopter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
35 lines (27 loc) · 976 Bytes
/
doc.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
/*
Package gopter contain the main interfaces of the GOlang Property TestER.
A simple property test might look like this:
func TestSqrt(t *testing.T) {
properties := gopter.NewProperties(nil)
properties.Property("greater one of all greater one", prop.ForAll(
func(v float64) bool {
return math.Sqrt(v) >= 1
},
gen.Float64Range(1, math.MaxFloat64),
))
properties.Property("squared is equal to value", prop.ForAll(
func(v float64) bool {
r := math.Sqrt(v)
return math.Abs(r*r-v) < 1e-10*v
},
gen.Float64Range(0, math.MaxFloat64),
))
properties.TestingRun(t)
}
Generally a property is just a function that takes GenParameters and produces
a PropResult:
type Prop func(*GenParameters) *PropResult
but usually you will use prop.ForAll, prop.ForAllNoShrink or arbitrary.ForAll.
There is also the commands package, which can be helpful for stateful testing.
*/
package gopter