-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarySearch_test.go
More file actions
41 lines (39 loc) · 835 Bytes
/
binarySearch_test.go
File metadata and controls
41 lines (39 loc) · 835 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
package main
import "testing"
func Test_binarySearch(t *testing.T) {
type args struct {
data []int
target int
low int
high int
}
tests := []struct {
name string
args args
wantIndex int
wantFound bool
}{
{
name: "Search",
args: args{
data: []int{1, 45, 76, 87, 94, 109, 555, 1003},
target: 555,
low: 0,
high: 8,
},
wantIndex: 6,
wantFound: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotIndex, gotFound := binarySearch(tt.args.data, tt.args.target, tt.args.low, tt.args.high)
if gotIndex != tt.wantIndex {
t.Errorf("binarySearch() gotIndex = %v, want %v", gotIndex, tt.wantIndex)
}
if gotFound != tt.wantFound {
t.Errorf("binarySearch() gotFound = %v, want %v", gotFound, tt.wantFound)
}
})
}
}