You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
863 B

package binarysearch_test
import (
"testing"
bs "git.jxs.me/leetgo/binarysearch"
"github.com/stretchr/testify/require"
)
func TestEmpty(t *testing.T) {
require.Equal(t, -1, bs.Search([]int{}, 7))
}
func TestSingle(t *testing.T) {
require.Equal(t, 0, bs.Search([]int{6}, 6))
}
func TestTwo(t *testing.T) {
require.Equal(t, -1, bs.Search([]int{2, 5}, 0))
}
func TestMulti(t *testing.T) {
require.Equal(t, 5, bs.Search([]int{1, 2, 3, 4, 5, 6, 7}, 6))
}
func TestMultiEnd(t *testing.T) {
require.Equal(t, 6, bs.Search([]int{1, 2, 3, 4, 5, 6, 7}, 7))
}
func TestMultiStart(t *testing.T) {
require.Equal(t, 0, bs.Search([]int{1, 2, 3, 4, 5, 6, 7}, 1))
}
func TestExample1(t *testing.T) {
require.Equal(t, 4, bs.Search([]int{-1, 0, 3, 5, 9, 12}, 9))
}
func TestExample2(t *testing.T) {
require.Equal(t, -1, bs.Search([]int{-1, 0, 3, 5, 9, 12}, 2))
}