1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-13 17:22:27 +08:00

feat: add FindLast func

This commit is contained in:
dudaodong
2022-01-24 15:28:47 +08:00
parent 8bb102cb6e
commit 1ad990ce9d
2 changed files with 43 additions and 1 deletions

View File

@@ -172,6 +172,20 @@ func TestFind(t *testing.T) {
assert.Equal(2, res)
}
func TestFindLast(t *testing.T) {
nums := []int{1, 2, 3, 4, 5}
even := func(i, num int) bool {
return num%2 == 0
}
res, ok := FindLast(nums, even)
if !ok {
t.Fatal("found nothing")
}
assert := internal.NewAssert(t, "TestFind")
assert.Equal(4, res)
}
func TestFindFoundNothing(t *testing.T) {
nums := []int{1, 1, 1, 1, 1, 1}
findFunc := func(i, num int) bool {
@@ -443,7 +457,7 @@ func TestDifferenceBy(t *testing.T) {
assert := internal.NewAssert(t, "TestDifferenceBy")
s1 := []int{1, 2, 3, 4, 5} //after add one: 2 3 4 5 6
s2 := []int{3, 4, 5} //after add one: 4 5 6
s2 := []int{3, 4, 5} //after add one: 4 5 6
addOne := func(i int, v int) int {
return v + 1
}