/
main.go
executable file
·86 lines (76 loc) · 1.64 KB
/
main.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
package main
import (
"context"
"fmt"
"reflect"
"sort"
"time"
"github.com/gladmo/leetcode/leet"
"github.com/gladmo/leetcode/questions/serial/medium/347/golang/solution"
)
func main() {
tests := []struct {
name string
input1 []int
input2 int
want []int
}{
{
name: "test-[1,1,2,3,3,4,2,4,5,2,2,2,3]-2",
input1: []int{1, 1, 2, 3, 3, 4, 2, 4, 5, 2, 2, 2, 3},
input2: 2,
want: []int{2, 3},
},
{
name: "test-[1,1,2,3,3,4,2,4,5,2,2,2,3]-3",
input1: []int{1, 2, 3, 3, 4, 2, 4, 5, 2, 2, 2, 3},
input2: 3,
want: []int{2, 3, 4},
},
{
name: "test-[1,1,1,2,2,3]-2",
input1: []int{1, 1, 1, 2, 2, 3},
input2: 2,
want: []int{1, 2},
},
{
name: "test-[1,1,1,2,2,3]-3",
input1: []int{1, 1, 1, 2, 2, 3},
input2: 3,
want: []int{1, 2, 3},
},
{
name: "test-[1,1,2,2,2,3]-3",
input1: []int{1, 1, 2, 2, 2, 3},
input2: 2,
want: []int{1, 2},
},
{
name: "test-[1]-1",
input1: []int{1},
input2: 1,
want: []int{1},
},
}
testLog := leet.NewTestLog(len(tests))
defer testLog.Render()
timeoutDuration := time.Second * 2
for idx, test := range tests {
// 超时检测
timeout := leet.Timeout(timeoutDuration, func(ctx context.Context, cancel context.CancelFunc) {
solution.Export(test.input1, test.input2)
cancel()
})
if timeout {
testLog.Fail(idx+1, test.name, "timeout")
continue
}
got := solution.Export(test.input1, test.input2)
sort.Ints(got)
if !reflect.DeepEqual(test.want, got) {
testLog.Fail(idx+1, test.name, fmt.Sprintf("want: %v, got %v.", test.want, got))
continue
}
testLog.Pass(idx+1, test.name)
}
}