update 05.03.24
This commit is contained in:
commit
026061851d
6 changed files with 74 additions and 0 deletions
22
main_test.go
Normal file
22
main_test.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBinarySearchWithWorkingTarget(t *testing.T) {
|
||||
nums := []int{2, 3, 5, 7, 8}
|
||||
target := 7
|
||||
resu, err := binarySearch(nums, target)
|
||||
if err != nil || resu != 3 {
|
||||
t.Errorf("Test failed! expected: %v, but got: %v", 3, resu)
|
||||
}
|
||||
}
|
||||
func TestBinarySearchWithNonWorkingTarget(t *testing.T) {
|
||||
nums := []int{1, 4, 5, 8, 9}
|
||||
target := 2
|
||||
resu, err := binarySearch(nums, target)
|
||||
if err == nil || resu != -1 {
|
||||
t.Errorf("Test failed! expected: %v, but got: %v", "binarySearch: your target is not found in the given array", err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue