-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_test.go
57 lines (45 loc) · 1.26 KB
/
search_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package array
import (
"testing"
)
func TestFind(t *testing.T) {
arr := Array[int]{1, 2, 3, 4, 5}
findFunc := func(item int, index int) bool {
return item == 3
}
expectedValue := 3
expectedIndex := 2
actualValue, actualIndex := arr.Find(findFunc)
if actualValue != expectedValue {
t.Errorf("Find() returned %v, expected %v", actualValue, expectedValue)
}
if actualIndex != expectedIndex {
t.Errorf("Find() returned index %v, expected %v", actualIndex, expectedIndex)
}
}
func TestFindIndex(t *testing.T) {
arr := Array[int]{1, 2, 3, 4, 5}
findFunc := func(item int, index int) bool {
return item == 3
}
expectedIndex := 2
actualIndex := arr.FindIndex(findFunc)
if actualIndex != expectedIndex {
t.Errorf("FindIndex() returned index %v, expected %v", actualIndex, expectedIndex)
}
}
func TestFindLast(t *testing.T) {
arr := Array[int]{1, 2, 3, 4, 5}
findFunc := func(item int, index int) bool {
return item == 3
}
expectedValue := 3
expectedIndex := 2
actualValue, actualIndex := arr.FindLast(findFunc)
if actualValue != expectedValue {
t.Errorf("FindLast() returned %v, expected %v", actualValue, expectedValue)
}
if actualIndex != expectedIndex {
t.Errorf("FindLast() returned index %v, expected %v", actualIndex, expectedIndex)
}
}