Beispiel #1
0
func benchmarkQSort(i int, b *testing.B) {
	for j := 0; j < b.N; j++ {
		b.StopTimer()
		values := perm(i)
		b.StartTimer()
		quicksort.Sort(values)
	}
}
Beispiel #2
0
func TestQSort(t *testing.T) {
	values := []int{9, 1, 20, 3, 6, 7}
	expected := []int{1, 3, 6, 7, 9, 20}

	quicksort.Sort(values)

	if !reflect.DeepEqual(values, expected) {
		t.Fatalf("expected %d, actual is %d", 1, values[0])
	}
}
Beispiel #3
0
func sortedRandomArray(n int) []int {
	sliced := rand.Perm(n * 20)[n : n*2-1]
	quicksort.Sort(sliced)
	return sliced
}