-
Notifications
You must be signed in to change notification settings - Fork 166
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
hashmap delete功能实现 #138
hashmap delete功能实现 #138
Conversation
Signed-off-by: Ming Deng <[email protected]>
Codecov Report
@@ Coverage Diff @@
## dev #138 +/- ##
==========================================
- Coverage 95.54% 95.48% -0.06%
==========================================
Files 36 36
Lines 1772 1818 +46
==========================================
+ Hits 1693 1736 +43
- Misses 62 64 +2
- Partials 17 18 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
mapx/hashmap.go
Outdated
return root.value, true | ||
} | ||
pre.next = root.next | ||
return root.value, true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个被删除节点的 node 要放回去 pool 里面
mapx/hashmap_test.go
Outdated
if err != nil { | ||
panic(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里改成 require.NoError(t, err),我记得这里别的测试用例也用了这种写法,都改成 require.NoError()
mapx/hashmap_test.go
Outdated
deleteKey testData | ||
wantVal any | ||
wantHashMap func() map[uint64]*node[testData, int] | ||
IsFound bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用小写 isFound
mapx/hashmap_test.go
Outdated
}, | ||
IsFound: true, | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个测试用例,就是测试 hash code 冲突,然后是删除队首元素的。
mapx/hashmap_test.go
Outdated
@@ -128,6 +128,140 @@ func TestHashMap(t *testing.T) { | |||
} | |||
|
|||
} | |||
func TestHashMap_Delete(t *testing.T) { | |||
testKV := []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我其实不太建议这里提前准备好所有的数据,我建议每个测试用例单独准备测试数据。这个和 Get 不一样,Get 是纯粹的查询,不会修改数据,因此相互之间没有影响。而这个删除操作,测试用例之间是有影响的,比如说你必须要在每一个 testcase 里面小心,确保前面的测试用例没有把你当前测试用例的数据删除掉。
这违背了我们设计单元测试保持每一个测试用例独立性的要求
No description provided.