-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_index_test.go
More file actions
39 lines (28 loc) · 806 Bytes
/
find_index_test.go
File metadata and controls
39 lines (28 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package js_array_method
import "testing"
func TestFindIndexWithCallback(t *testing.T) {
users := []User{{Id: 10, Name: "John"}, {Id: 11, Name: "Doe"}, {Id: 12, Name: "Sabrina"}}
index := FindIndex(users, func(user User, _ int) bool {
return user.Name == "Doe"
})
if index == -1 || index == 2 {
t.Errorf("Expected 1 got %d", index)
}
index = FindIndex(users, func(user User, _ int) bool {
return user.Name == "creator"
})
if index != -1 {
t.Errorf("Expected -1 got %d", index)
}
}
func TestFindIndexWithoutCallback(t *testing.T) {
users := []string{"User1", "User2", "User3", "User4"}
index := FindIndex(users, "User1")
if index != 0 {
t.Errorf("Expected 0 got %d", index)
}
index = FindIndex(users, "User5")
if index != -1 {
t.Errorf("Expected -1 got %d", index)
}
}