Skip to content

Commit 997afe8

Browse files
committed
improve-constructions-coverage
1 parent 6e20d9a commit 997afe8

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

construction/listnode/listnode.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ type ListNode struct {
1010
// MakeListNode 将连续结构的数组转化成 -> 单链结构数据的 -> 取址
1111
func MakeListNode(is []int) *ListNode {
1212
if len(is) == 0 {
13-
return nil
13+
return &ListNode{}
1414
}
15-
1615
res := &ListNode{
1716
Val: is[0],
1817
}

construction/listnode/listnode_test.go

+38-4
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,46 @@ func Test_OK(t *testing.T) {
4848
one: MakeListNode([]int{1, 6, 4}),
4949
},
5050
},
51-
};
51+
question{
52+
p: para{
53+
one: MakeListNode([]int{1, 6}),
54+
},
55+
a: ans{
56+
one: MakeListNode([]int{1, 6}),
57+
},
58+
},
59+
question{
60+
p: para{
61+
one: MakeListNode([]int{1}),
62+
},
63+
a: ans{
64+
one: MakeListNode([]int{1}),
65+
},
66+
},
67+
question{
68+
p: para{
69+
one: MakeListNode([]int{}),
70+
},
71+
a: ans{
72+
one: &ListNode{},
73+
},
74+
},
75+
}
5276

5377
for _, q := range qs {
5478
a, p := q.a, q.p
55-
ast.Equal(a.one.Val, p.one.Val, "输入:%v", p)
56-
ast.Equal(a.one.Next.Val, p.one.Next.Val, "输入:%v", p)
57-
ast.Equal(a.one.Next.Next.Val, p.one.Next.Next.Val, "输入:%v", p)
79+
if a.one != nil {
80+
ast.Equal(a.one.Val, p.one.Val, "输入:%v", p)
81+
} else {
82+
ast.Equal(nil, p.one, "输入:%v", p)
83+
ast.Equal(nil, a.one, "输入:%v", p)
84+
}
85+
if a.one != nil && a.one.Next != nil {
86+
ast.Equal(a.one.Next.Val, p.one.Next.Val, "输入:%v", p)
87+
}
88+
if a.one != nil && a.one.Next != nil && a.one.Next.Next != nil {
89+
ast.Equal(a.one.Next.Next.Val, p.one.Next.Next.Val, "输入:%v", p)
90+
}
91+
5892
}
5993
}

coverage.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ www/leetcode/5.LongestPalindromicSubstring/main.go:6.29,8.5 1 7
157157
www/leetcode/5.LongestPalindromicSubstring/main.go:10.8,12.33 1 11
158158
www/leetcode/5.LongestPalindromicSubstring/main.go:12.33,13.29 1 4
159159
www/leetcode/5.LongestPalindromicSubstring/main.go:13.29,15.5 1 2
160-
www/leetcode/5.LongestPalindromicSubstring/main.go:21.41,22.16 1 2
160+
www/leetcode/5.LongestPalindromicSubstring/main.go:21.41,22.16 1 3
161161
www/leetcode/5.LongestPalindromicSubstring/main.go:25.2,26.30 2 2
162162
www/leetcode/5.LongestPalindromicSubstring/main.go:35.2,35.19 1 2
163-
www/leetcode/5.LongestPalindromicSubstring/main.go:22.16,24.3 1 0
163+
www/leetcode/5.LongestPalindromicSubstring/main.go:22.16,24.3 1 1
164164
www/leetcode/5.LongestPalindromicSubstring/main.go:26.30,27.36 1 7
165165
www/leetcode/5.LongestPalindromicSubstring/main.go:27.36,30.35 2 18
166166
www/leetcode/5.LongestPalindromicSubstring/main.go:30.35,32.5 1 3
@@ -235,8 +235,8 @@ www/leetcode/IBM/3.重复的字符串个数/main.go:3.38,5.19 2 1
235235
www/leetcode/IBM/3.重复的字符串个数/main.go:8.2,8.12 1 1
236236
www/leetcode/IBM/3.重复的字符串个数/main.go:5.19,7.3 1 8
237237
mode: atomic
238-
www/leetcode/construction/listnode/listnode.go:11.39,12.18 1 6
239-
www/leetcode/construction/listnode/listnode.go:16.2,21.31 3 6
240-
www/leetcode/construction/listnode/listnode.go:26.2,26.12 1 6
241-
www/leetcode/construction/listnode/listnode.go:12.18,14.3 1 0
242-
www/leetcode/construction/listnode/listnode.go:21.31,24.3 2 18
238+
www/leetcode/construction/listnode/listnode.go:11.39,12.18 1 11
239+
www/leetcode/construction/listnode/listnode.go:15.2,20.31 3 10
240+
www/leetcode/construction/listnode/listnode.go:25.2,25.12 1 10
241+
www/leetcode/construction/listnode/listnode.go:12.18,14.3 1 1
242+
www/leetcode/construction/listnode/listnode.go:20.31,23.3 2 20

0 commit comments

Comments
 (0)