forked from wufenggirl/LeetCode-in-Golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-comments_test.go
executable file
·139 lines (126 loc) · 1.79 KB
/
remove-comments_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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package problem0722
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// tcs is testcase slice
var tcs = []struct {
source []string
ans []string
}{
{
[]string{
"struct Node{",
" /*/ declare members;/**/",
" int size;",
" /**/int val;",
"};",
},
[]string{
"struct Node{",
" ",
" int size;",
" int val;",
"};",
},
},
{
[]string{
"a//*b//*c",
"blank",
"d//*e/*/f",
},
[]string{
"a",
"blank",
"d",
},
},
{
[]string{
"/*Test program */",
"int main()",
"{ ",
" // variable declaration ",
"int a, b, c;",
"/* This is a test",
" multiline ",
" comment for ",
" testing */",
"a = b + c;",
"}",
},
[]string{
"int main()",
"{ ",
" ",
"int a, b, c;",
"a = b + c;",
"}",
},
},
{
[]string{
"main() {",
" Node* p;",
" /* declare a Node",
" /*float f = 2.0",
" p->val = f;",
" /**/",
" p->val = 1;",
" //*/ cout << success;*/",
"}",
" ",
},
[]string{
"main() {",
" Node* p;",
" ",
" p->val = 1;",
" ",
"}",
" ",
},
},
{
[]string{
"void func(int k) {",
"// this function does nothing /*",
" k = k*2/4;",
" k = k/2;*/",
"}",
},
[]string{
"void func(int k) {",
" k = k*2/4;",
" k = k/2;*/",
"}",
},
},
{
[]string{
"a/*comment",
"line",
"more_comment*/b",
},
[]string{
"ab",
},
},
// 可以有多个 testcase
}
func Test_fn(t *testing.T) {
ast := assert.New(t)
for _, tc := range tcs {
fmt.Printf("~~%v~~\n", tc)
ast.Equal(tc.ans, removeComments(tc.source), "输入:%v", tc)
}
}
func Benchmark_fn(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, tc := range tcs {
removeComments(tc.source)
}
}
}