Skip to content

Commit 06db884

Browse files
committed
提高测试覆盖率
1 parent fc35021 commit 06db884

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed

6.ZigZagConversion/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## [5. Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)
2+
3+
###### 2019/02/17
4+
5+
> #### 思路
6+
> abcbd
7+
> 二次循环
8+
> a
9+
> ab
10+
> abc
11+
> abcb
12+
> abcbd
13+
> b
14+
> bc
15+
> bcb -> 检测是否是是回文函数
16+
17+
18+
### TODO
19+
- [x] 测试用例通过
20+
- [ ] 双层for循环遍历一般都很慢,应该尽量避免写O(m*n)代码

6.ZigZagConversion/main.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func convert(s string, numRows /*总列数*/int) string {
6+
//
7+
container := [][]string{}
8+
9+
numCols := len(s) / numRows // 总行数
10+
numMid := numRows - 2
11+
fmt.Println(s, numCols, container, numMid)
12+
return s
13+
}
14+
15+
func main() {
16+
fmt.Println(convert("PAYPALISHIRING", 4))
17+
}

6.ZigZagConversion/main_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
type para struct {
10+
str string
11+
row int
12+
}
13+
14+
type ans struct {
15+
str string
16+
}
17+
18+
type question struct {
19+
p para
20+
a ans
21+
}
22+
23+
func Test_OK(t *testing.T) {
24+
ast := assert.New(t)
25+
26+
qs := []question{
27+
question{
28+
p: para{
29+
str: "PAYPALISHIRING",
30+
row: 3,
31+
},
32+
a: ans{
33+
str: "PAHNAPLSIIGYIR",
34+
},
35+
},
36+
question{
37+
p: para{
38+
str: "PAYPALISHIRING",
39+
row: 4,
40+
},
41+
a: ans{
42+
str: "PINALSIGYAHRPI",
43+
},
44+
},
45+
}
46+
47+
for _, q := range qs {
48+
a, p := q.a, q.p
49+
ast.Equal(a.str, convert(p.str,p.row), "输入:%v", p)
50+
}
51+
52+
// ast.Panics(func() { longestPalindrome([]int{}, []int{}) }, "对空切片求中位数,却没有panic")
53+
54+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
[![LeetCode 排名](https://img.shields.io/badge/pengliheng-6-blue.svg)](https://leetcode.com/pengliheng/)
3+
[![LeetCode 完成数](https://img.shields.io/badge/pengliheng-6-blue.svg)](https://leetcode.com/pengliheng/)
44
[![codecov](https://codecov.io/gh/pengliheng/leetcode/branch/master/graph/badge.svg)](https://codecov.io/gh/pengliheng/leetcode)
55
[![Build Status](https://www.travis-ci.org/pengliheng/leetcode.svg?branch=master)](https://www.travis-ci.org/pengliheng/leetcode)
66

profile.out

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mode: atomic
2+
www/leetcode/6.ZigZagConversion/main.go:5.57,13.2 5 2
3+
www/leetcode/6.ZigZagConversion/main.go:15.13,17.2 1 0

test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ for d in $(go list ./... | grep -v vendor); do
1010
cat profile.out >> coverage.txt
1111
rm profile.out
1212
fi
13-
done
13+
done
14+
bash <(curl -s https://codecov.io/bash) -t 47a37090-9a90-4358-8e69-d81d5ce4f9e2

0 commit comments

Comments
 (0)