Example #1
0
func BenchmarkSortSlice(b *testing.B) {
	const sz = 1000
	b.SetBytes(sz)
	for i := 0; i < b.N; i++ {
		b.StopTimer()
		ints := make([]sort.Item, sz)
		for i := 0; i < sz; i++ {
			ints[i] = Int(rand.Intn(8 * sz / 10))
		}
		b.StartTimer()
		ints = sort.SortSlice(ints)
	}
}
Example #2
0
func TestMakeSortSlice(t *testing.T) {
	const sz = 1000
	ints := make([]sort.Item, sz)
	for i := 0; i < sz; i++ {
		ints[i] = Int(rand.Intn(8 * sz / 10))
	}
	count := 0
	var lasti sort.Item
	for _, i := range sort.SortSlice(ints) {
		if count != 0 && i.Precedes(lasti) {
			t.Errorf("Unexpected order: %v : %v", i, lasti)
		}
		count++
		lasti = i
	}
	if count != sz {
		t.Errorf("Expected count %v: got %v", sz, count)
	}
}