From 44e930b71107310eae55060cf0aa2cac7089d239 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 8 Aug 2020 13:27:43 +0100 Subject: fortune not found Quick commit --- sort/quick.go | 4 ++-- sort/sort_test.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'sort') diff --git a/sort/quick.go b/sort/quick.go index f58f046..5dbcfe5 100644 --- a/sort/quick.go +++ b/sort/quick.go @@ -31,13 +31,13 @@ func quickPartition(a ds.ArrayList, lo, hi int) int { v := a[lo] // Partitioning item for { - for i++; a[i].Lower(v); i++ { + for i++; a[i] < v; i++ { if i == hi { break } } - for j--; v.Lower(a[j]); j-- { + for j--; v < a[j]; j-- { if j == lo { break } diff --git a/sort/sort_test.go b/sort/sort_test.go index 899669b..fa515d7 100644 --- a/sort/sort_test.go +++ b/sort/sort_test.go @@ -10,8 +10,9 @@ import ( var benchResult ds.ArrayList var benchResultInt []int -const minLength int = 100 -const maxLength int = 10000 +const minLength int = 1 +const maxLength int = 1000000 +const maxSlowLength int = 100000 var arrayListCache map[string]ds.ArrayList @@ -19,13 +20,13 @@ type sortAlgorithm func(ds.ArrayList) ds.ArrayList type sortAlgorithmInt func([]int) []int func TestSelectionSort(t *testing.T) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { test(Selection, i, t) } } func TestInsertionSort(t *testing.T) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { test(Insertion, i, t) } } @@ -82,13 +83,13 @@ func TestShuffleSort(t *testing.T) { } func BenchmarkInsertionSort(b *testing.B) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { benchmark(Insertion, i, b) } } func BenchmarkSelectionSort(b *testing.B) { - for i := minLength; i <= maxLength; i *= 10 { + for i := minLength; i <= maxSlowLength; i *= 10 { benchmark(Selection, i, b) } } @@ -204,6 +205,7 @@ func makeRandomIntegers(length, max int) ds.ArrayList { return a } a := ds.RandomIntegers(length, max) + a = Shuffle(a) arrayListCache[key] = a return a } -- cgit v1.2.3