| 6 | ) |
| 7 | |
| 8 | func TestBinary(t *testing.T) { |
| 9 | for _, test := range searchTests { |
| 10 | actualValue, actualError := Binary(test.data, test.key, 0, len(test.data)-1) |
| 11 | if actualValue != test.expected { |
| 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) |
| 13 | } |
| 14 | if !errors.Is(test.expectedError, actualError) { |
| 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) |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestBinaryIterative(t *testing.T) { |
| 21 | for _, test := range searchTests { |