mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-12 00:32:27 +08:00
Slice: find nothing case (#11)
The current behavior can result into wired edge cases. **Current behavior** if find was unsuccessfully then it will return the first element of the slice **Desired behavior** if find was unsuccessfully then it should return negative ok and a none value
This commit is contained in:
@@ -190,13 +190,28 @@ func TestFind(t *testing.T) {
|
||||
even := func(i, num int) bool {
|
||||
return num%2 == 0
|
||||
}
|
||||
res := Find(nums, even)
|
||||
res, ok := Find(nums, even)
|
||||
if !ok {
|
||||
t.Fatal("found nothing")
|
||||
}
|
||||
|
||||
if res != 2 {
|
||||
internal.LogFailedTestInfo(t, "Find", nums, 2, res)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindFoundNothing(t *testing.T) {
|
||||
nums := []int{1, 1, 1, 1, 1, 1}
|
||||
findFunc := func(i, num int) bool {
|
||||
return num > 1
|
||||
}
|
||||
_, ok := Find(nums, findFunc)
|
||||
if ok {
|
||||
t.Fatal("found something")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlattenDeep(t *testing.T) {
|
||||
input := [][][]string{{{"a", "b"}}, {{"c", "d"}}}
|
||||
expected := []string{"a", "b", "c", "d"}
|
||||
|
||||
Reference in New Issue
Block a user