list: add DeleteIf method (#50)

DeleteIf delete all satisfying f(data[i]), returns count of removed elements
This commit is contained in:
donutloop authored and GitHub committed 2022-07-23 18:52:29 +08:00
1 parent 0299c454ab
commit 3d7600a9e4
3 files changed
+70 -1

No files matched your search

+14
View File
@@ -331,3 +331,17 @@ func BenchmarkSubSlice(b *testing.B) {
list.SubList(2, 5)
}
}
func TestDeleteIf(t *testing.T) {
assert := internal.NewAssert(t, "TestDeleteIf")
list := NewList([]int{1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, 1})
count := list.DeleteIf(func(a int) bool { return a == 1 })
assert.Equal([]int{2, 3, 4}, list.Data())
assert.Equal(12, count)
count = list.DeleteIf(func(a int) bool { return a == 5 })
assert.Equal([]int{2, 3, 4}, list.Data())
assert.Equal(0, count)
}