1
1
package search
2
2
3
- import "testing"
3
+ import (
4
+ "errors"
5
+ "testing"
6
+ )
4
7
5
8
func TestBinary (t * testing.T ) {
6
9
for _ , test := range searchTests {
7
10
actualValue , actualError := Binary (test .data , test .key , 0 , len (test .data )- 1 )
8
11
if actualValue != test .expected {
9
12
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected '%d', get '%d'" , test .name , test .data , test .key , test .expected , actualValue )
10
13
}
11
- if actualError != test .expectedError {
14
+ if ! errors . Is ( test .expectedError , actualError ) {
12
15
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected error '%s', get error '%s'" , test .name , test .data , test .key , test .expectedError , actualError )
13
16
}
14
17
}
@@ -20,7 +23,7 @@ func TestBinaryIterative(t *testing.T) {
20
23
if actualValue != test .expected {
21
24
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected '%d', get '%d'" , test .name , test .data , test .key , test .expected , actualValue )
22
25
}
23
- if actualError != test .expectedError {
26
+ if ! errors . Is ( test .expectedError , actualError ) {
24
27
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected error '%s', get error '%s'" , test .name , test .data , test .key , test .expectedError , actualError )
25
28
}
26
29
}
@@ -32,7 +35,7 @@ func TestLowerBound(t *testing.T) {
32
35
if actualValue != test .expected {
33
36
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected '%d', get '%d'" , test .name , test .data , test .key , test .expected , actualValue )
34
37
}
35
- if actualError != test .expectedError {
38
+ if ! errors . Is ( test .expectedError , actualError ) {
36
39
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected error '%s', get error '%s'" , test .name , test .data , test .key , test .expectedError , actualError )
37
40
}
38
41
}
@@ -44,7 +47,7 @@ func TestUpperBound(t *testing.T) {
44
47
if actualValue != test .expected {
45
48
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected '%d', get '%d'" , test .name , test .data , test .key , test .expected , actualValue )
46
49
}
47
- if actualError != test .expectedError {
50
+ if ! errors . Is ( test .expectedError , actualError ) {
48
51
t .Errorf ("test '%s' failed: input array '%v' with key '%d', expected error '%s', get error '%s'" , test .name , test .data , test .key , test .expectedError , actualError )
49
52
}
50
53
}
0 commit comments