Beispiel #1
0
func benchInt(b *testing.B, size int, algorithm func(sort.Interface)) {
	b.StopTimer()
	for i := 0; i < b.N; i++ {
		data := make([]int, size)
		for i := 0; i < len(data); i++ {
			data[i] = i ^ 0xcccc
		}
		b.StartTimer()
		sorting.Ints(data, algorithm)
		b.StopTimer()
	}
}
Beispiel #2
0
func TestInts(t *testing.T) {
	data := ints

	for _, alg := range algorithms {
		sorting.Ints(data[:], alg)
		if !sort.IntsAreSorted(data[:]) {
			t.Errorf("%v\n", util.GetFuncName(alg))
			t.Errorf("sorted: %v\n", ints)
			t.Errorf("   got: %v\n", data)
		}
	}
}
Beispiel #3
0
func TestSortLarge_Random(t *testing.T) {
	n := 10000
	if testing.Short() {
		n /= 100
	}
	data := make([]int, n)
	for i := 0; i < len(data); i++ {
		data[i] = rand.Intn(100)
	}
	if sort.IntsAreSorted(data) {
		t.Fatalf("terrible rand.rand")
	}

	for _, alg := range algorithms {
		sorting.Ints(data, alg)
		if !sort.IntsAreSorted(data) {
			t.Errorf("%v failed to sort 10K ints\n", util.GetFuncName(alg))
		}
	}
}