Skip to content

Commit 2f4cdf7

Browse files
committed
update a solution
1 parent 1e42fcc commit 2f4cdf7

File tree

4 files changed

+45
-27
lines changed

4 files changed

+45
-27
lines changed

SUMMARY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,7 @@
193193
* [0198.House-Robber](docs/leetcode/101-200/0198.house-robber.md)
194194
* [0199.Binary-Tree-Right-Side-View](docs/leetcode/101-200/0199.binary-tree-right-side-view.md)
195195
* [0200.Number-of-Islands](docs/leetcode/101-200/0200.number-of-islands.md)
196-
196+
* [201-200](docs/leetcode/101-200/README.md)
197+
* [0101.Symmetric-Tree](docs/leetcode/101-200/0101.symmetric-tree.md)
198+
* [301-400](docs/leetcode/101-200/README.md)
199+
* [0322.Symmetric-Tree](docs/leetcode/301-400/0322.coin-change.md)

docs/leetcode/301-400/0322.coin-change.md

Whitespace-only changes.

docs/leetcode/301-400/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module "301-400"
Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,55 @@
11
package Solution
22

33
import (
4+
"github.com/stretchr/testify/assert"
45
"reflect"
5-
"strconv"
6+
"runtime"
67
"testing"
78
)
89

9-
func TestSolution(t *testing.T) {
10-
// 测试用例
11-
cases := []struct {
12-
name string
13-
inputs []int
14-
amount int
15-
expect int
16-
}{
17-
{"TestCase", []int{1, 2, 5}, 11, 3},
18-
{"TestCase", []int{2}, 3, -1},
19-
}
10+
// solution func Info
11+
type SolutionFuncType func([]int, int) int
2012

21-
// 开始测试
22-
for i, c := range cases {
23-
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
24-
got := coinChange(c.inputs, c.amount)
25-
if !reflect.DeepEqual(got, c.expect) {
26-
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
27-
c.expect, got, c.inputs)
28-
}
29-
})
30-
}
13+
var SolutionFuncList = []SolutionFuncType{
14+
coinChange,
3115
}
3216

33-
// 压力测试
34-
func BenchmarkSolution(b *testing.B) {
17+
// test info struct
18+
type Case struct {
19+
name string
20+
coins []int
21+
amount int
22+
expect int
23+
}
3524

25+
// test case
26+
var cases = []Case{
27+
{
28+
name: "TestCase 1",
29+
coins: []int{1, 2, 5},
30+
amount: 11,
31+
expect: 3,
32+
},
33+
{
34+
name: "TestCase 2",
35+
coins: []int{2},
36+
amount: 3,
37+
expect: -1,
38+
},
3639
}
3740

38-
// 使用案列
39-
func ExampleSolution() {
41+
// TestSolution Example for solution test cases
42+
func TestSolution(t *testing.T) {
43+
ast := assert.New(t)
4044

45+
for _, f := range SolutionFuncList {
46+
for _, c := range cases {
47+
t.Run(c.name, func(t *testing.T) {
48+
actual := f(c.coins, c.amount)
49+
ast.Equal(c.expect, actual,
50+
"func: %v case: %v ",
51+
runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), c.name)
52+
})
53+
}
54+
}
4155
}

0 commit comments

Comments
 (0)