-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
executable file
·62 lines (50 loc) · 1 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
package main
import (
"context"
"fmt"
"reflect"
"time"
"github.com/gladmo/leetcode/leet"
"github.com/gladmo/leetcode/questions/serial/easy/561/golang/solution"
)
func main() {
/*
[1,4,3,2]
*/
tests := []struct {
name string
input []int
want int
}{
{
name: "test-[1,4,3,2]",
input: []int{1, 4, 3, 2},
want: 4,
},
{
name: "test-[6,2,6,5,1,2]",
input: []int{6, 2, 6, 5, 1, 2},
want: 9,
},
}
testLog := leet.NewTestLog(len(tests))
defer testLog.Render()
timeoutDuration := time.Second * 2
for idx, test := range tests {
// 超时检测
got := test.want
timeout := leet.Timeout(timeoutDuration, func(ctx context.Context, cancel context.CancelFunc) {
got = solution.Export(test.input)
cancel()
})
if timeout {
testLog.Fail(idx+1, test.name, "timeout")
continue
}
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)
}
}