forked from eduncan911/mspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumop_test.go
42 lines (36 loc) · 910 Bytes
/
sumop_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
package bdd
import (
"fmt"
)
// TestInt is a named type after int for test purposes.
type TestInt int
// Sum is a function to sum a TestInt to int of TestInt types.
func (t TestInt) Sum(a interface{}) (n TestInt) {
switch val := a.(type) {
case int:
n = t + TestInt(val)
case TestInt:
n = t + val
default:
n = TestInt(0)
}
return
}
// TestSumOp is a test structure to suite test a struct.
type TestSumOp struct {
LastResultAsString string `json:"last_result" yaml:"last_result"`
Handicap TestInt `json:"handicap" yaml:"handicap"`
}
// Sum is a test method to suite test a struct.
func (s *TestSumOp) Sum(a, b int) (x int) {
x = int(TestInt(a).Sum(b).Sum(s.Handicap))
s.LastResultAsString = fmt.Sprintf("%v", x)
return
}
// NewTestSumOp creates a new TestSumOp with a handicap h.
func NewTestSumOp(h int) (t *TestSumOp) {
t = &TestSumOp{
Handicap: TestInt(h),
}
return
}