1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 15:12:26 +08:00

list: add DeleteIf method (#50)

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

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)
}