Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linked_list完成delete方法,linked_list_test新增delete测试用例 #38

Merged
merged 15 commits into from
Aug 20, 2022

Conversation

mousseqin
Copy link
Contributor

linked_list完成delete方法,linked_list_test新增delete测试用例

@codecov
Copy link

codecov bot commented Aug 19, 2022

Codecov Report

Merging #38 (f8f37a5) into dev (2f5a0ab) will increase coverage by 1.21%.
The diff coverage is 90.90%.

@@            Coverage Diff             @@
##              dev      #38      +/-   ##
==========================================
+ Coverage   88.54%   89.76%   +1.21%     
==========================================
  Files           7        7              
  Lines         262      293      +31     
==========================================
+ Hits          232      263      +31     
+ Misses         27       26       -1     
- Partials        3        4       +1     
Impacted Files Coverage Δ
list/linked_list.go 88.38% <90.90%> (+2.90%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

// 删除head
if index == 0 {
delVal = l.head.val
l.head.next.prev = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这里会不会 panic?如果我只有一个元素,然后恰好被你删了,head.next 其实是 nil

Comment on lines 146 to 147
tmp := l.tail.prev
l.tail = tmp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l.tail = l.tail.prev 这样应该也可以吧?不需要 tmp 这个中间变量

Comment on lines 149 to 169
{
name: "delete num to index 1",
list: NewLinkedListOf[int]([]int{11, 22, 33, 44, 55}),
index: 1,
delVal: 22,
wantLinkedList: NewLinkedListOf([]int{11, 33, 44, 55}),
},
{
name: "delete num to index 2",
list: NewLinkedListOf[int]([]int{11, 22, 33, 44, 55}),
index: 2,
delVal: 33,
wantLinkedList: NewLinkedListOf([]int{11, 22, 44, 55}),
},
{
name: "delete num to index 3",
list: NewLinkedListOf[int]([]int{11, 22, 33, 44, 55}),
index: 3,
delVal: 44,
wantLinkedList: NewLinkedListOf([]int{11, 22, 33, 55}),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这三个测试用例,你只需要保留一个就可以,因为它们其实都命中你删除中间结点的那一个部分。此外,你还需要提供一个额外的测试用例:只有一个元素,然后被你删掉的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这三个测试用例,你只需要保留一个就可以,因为它们其实都命中你删除中间结点的那一个部分。此外,你还需要提供一个额外的测试用例:只有一个元素,然后被你删掉的

好的

@flycash flycash merged commit 0efba37 into ecodeclub:dev Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants