-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathSolution_test.go
57 lines (48 loc) · 957 Bytes
/
Solution_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
package Solution
import (
"reflect"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
// solution func Info
type SolutionFuncType func([]int, int) []int
var SolutionFuncList = []SolutionFuncType{
twoSum,
}
// test info struct
type Case struct {
name string
inputs []int
target int
expect []int
}
// test case
var cases = []Case{
{
name: "TestCase 1",
inputs: []int{2, 7, 11, 15},
target: 9,
expect: []int{2, 7},
},
{
name: "TestCase 2",
inputs: []int{10, 26, 30, 31, 47, 60},
target: 40,
expect: []int{10, 30},
},
}
// TestSolution Example for solution test cases
func TestSolution(t *testing.T) {
ast := assert.New(t)
for _, f := range SolutionFuncList {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
actual := f(c.inputs, c.target)
ast.Equal(c.expect, actual,
"func: %v case: %v ",
runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), c.name)
})
}
}
}