-
Notifications
You must be signed in to change notification settings - Fork 40
/
prop_result.go
109 lines (99 loc) · 2.67 KB
/
prop_result.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gopter
type propStatus int
const (
// PropProof THe property was proved (i.e. it is known to be correct and will be always true)
PropProof propStatus = iota
// PropTrue The property was true this time
PropTrue
// PropFalse The property was false this time
PropFalse
// PropUndecided The property has no clear outcome this time
PropUndecided
// PropError The property has generated an error
PropError
)
func (s propStatus) String() string {
switch s {
case PropProof:
return "PROOF"
case PropTrue:
return "TRUE"
case PropFalse:
return "FALSE"
case PropUndecided:
return "UNDECIDED"
case PropError:
return "ERROR"
}
return ""
}
// PropResult contains the result of a property
type PropResult struct {
Status propStatus
Error error
ErrorStack []byte
Args []*PropArg
Labels []string
}
// NewPropResult create a PropResult with label
func NewPropResult(success bool, label string) *PropResult {
if success {
return &PropResult{
Status: PropTrue,
Labels: []string{label},
Args: make([]*PropArg, 0),
}
}
return &PropResult{
Status: PropFalse,
Labels: []string{label},
Args: make([]*PropArg, 0),
}
}
// Success checks if the result was successful
func (r *PropResult) Success() bool {
return r.Status == PropTrue || r.Status == PropProof
}
// WithArgs sets argument descriptors to the PropResult for reporting
func (r *PropResult) WithArgs(args []*PropArg) *PropResult {
r.Args = args
return r
}
// AddArgs add argument descriptors to the PropResult for reporting
func (r *PropResult) AddArgs(args ...*PropArg) *PropResult {
r.Args = append(r.Args, args...)
return r
}
// And combines two PropResult by an and operation.
// The resulting PropResult will be only true if both PropResults are true.
func (r *PropResult) And(other *PropResult) *PropResult {
switch {
case r.Status == PropError:
return r
case other.Status == PropError:
return other
case r.Status == PropFalse:
return r
case other.Status == PropFalse:
return other
case r.Status == PropUndecided:
return r
case other.Status == PropUndecided:
return other
case r.Status == PropProof:
return r.mergeWith(other, other.Status)
case other.Status == PropProof:
return r.mergeWith(other, r.Status)
case r.Status == PropTrue && other.Status == PropTrue:
return r.mergeWith(other, PropTrue)
default:
return r
}
}
func (r *PropResult) mergeWith(other *PropResult, status propStatus) *PropResult {
return &PropResult{
Status: status,
Args: append(append(make([]*PropArg, 0, len(r.Args)+len(other.Args)), r.Args...), other.Args...),
Labels: append(append(make([]string, 0, len(r.Labels)+len(other.Labels)), r.Labels...), other.Labels...),
}
}