-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindexof_test.go
More file actions
44 lines (32 loc) · 832 Bytes
/
Copy pathindexof_test.go
File metadata and controls
44 lines (32 loc) · 832 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
40
41
42
43
44
package goulash
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIndexOf(t *testing.T) {
t.Run("IndexOfFound", func(t *testing.T) {
numbers := []int{1, 2, 3, 4, 5}
index := IndexOf(numbers, 3)
assert.Equal(t, 2, index)
})
t.Run("IndexOfNotFound", func(t *testing.T) {
numbers := []int{1, 2, 3, 4, 5}
index := IndexOf(numbers, 10)
assert.Equal(t, -1, index)
})
t.Run("IndexOfFirst", func(t *testing.T) {
numbers := []int{1, 2, 3, 2, 5}
index := IndexOf(numbers, 2)
assert.Equal(t, 1, index)
})
t.Run("IndexOfStrings", func(t *testing.T) {
words := []string{"hello", "world", "go"}
index := IndexOf(words, "world")
assert.Equal(t, 1, index)
})
t.Run("IndexOfEmpty", func(t *testing.T) {
var empty []int
index := IndexOf(empty, 1)
assert.Equal(t, -1, index)
})
}