func testBSearch(sorted []int, t *testing.T) { expected := rand.Intn(len(sorted) - 1) target := sorted[expected] found := binarysearch.Search(sorted, target) if found != expected { t.Fatalf("expected %d, actual is %d", expected, found) } }
func benchmarkBSearch(sorted []int, b *testing.B) { for j := 0; j < b.N; j++ { target := sorted[rand.Intn(len(sorted)-1)] binarysearch.Search(sorted, target) } }