-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathret2_test.go
47 lines (38 loc) · 893 Bytes
/
ret2_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
package testing_test
import (
"errors"
"math"
"testing"
. "github.com/rocketlaunchr/testing-go"
)
var errInvalidInput = errors.New("invalid input")
func sqrt(Panic bool, in float64) (float64, error) {
if Panic {
panic("panic")
}
if in < 0 {
return 0, errInvalidInput
}
return math.Sqrt(in), nil
}
func TestRet2(t *testing.T) {
testCases := []struct {
shouldPanic bool
in float64
ExpOut interface{}
ExpErr error
}{
// Test panic
{true, 0, Not{"abcd"}, PanicExpected},
{false, 0, 0.0, Not{PanicExpected}},
{false, 0, Not{1.0}, Not{PanicExpected}},
{false, -1, Not{"abcd"}, errInvalidInput},
{false, 9, 3.0, Not{errInvalidInput}},
}
tcfg := NewTestConfig(t)
for idx, tc := range testCases {
tcfg.Run2(Sprintf("[%d]: %v", idx, tc.in), tc, func(t *testing.T) (interface{}, error) {
return sqrt(tc.shouldPanic, tc.in)
})
}
}