예제 #1
0
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)
	}
}
예제 #2
0
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)
	}
}