From 6c598a53d3366d8ff7250bdc1ce29fa4c36ec246 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Jul 2020 09:44:02 +0100 Subject: better testing --- sort/insertion_test.go | 9 +++------ sort/selection_test.go | 9 +++------ sort/test.go | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 sort/test.go (limited to 'sort') diff --git a/sort/insertion_test.go b/sort/insertion_test.go index afec414..7be863d 100644 --- a/sort/insertion_test.go +++ b/sort/insertion_test.go @@ -1,7 +1,6 @@ package sort import ( - "algorithms/ds" "testing" ) @@ -11,10 +10,8 @@ func BenchmarkInsertion(b *testing.B) { benchmark("Insertion", 1000, Insertion, b) } -func TestInsertion1000(t *testing.T) { - a := ds.RandomIntegers(1000, 1000) - a = Insertion(a) - if !Sorted(a) { - t.Errorf("Array not sorted: %v", a) +func TestInsertion(t *testing.T) { + for i := 1; i <= 1000; i *= 10 { + test("Insertion", i, Insertion, t) } } diff --git a/sort/selection_test.go b/sort/selection_test.go index c5d6beb..f432474 100644 --- a/sort/selection_test.go +++ b/sort/selection_test.go @@ -1,7 +1,6 @@ package sort import ( - "algorithms/ds" "testing" ) @@ -11,10 +10,8 @@ func BenchmarkSelection(b *testing.B) { benchmark("Selection", 1000, Selection, b) } -func TestSelection1000(t *testing.T) { - a := ds.RandomIntegers(1000, 1000) - a = Selection(a) - if !Sorted(a) { - t.Errorf("Array not sorted: %v", a) +func TestSelection(t *testing.T) { + for i := 1; i <= 1000; i *= 10 { + test("Selection", i, Selection, t) } } diff --git a/sort/test.go b/sort/test.go new file mode 100644 index 0000000..fa12555 --- /dev/null +++ b/sort/test.go @@ -0,0 +1,19 @@ +package sort + +import ( + "algorithms/ds" + "fmt" + "testing" +) + +func test(name string, length int, sort func([]ds.Comparer) []ds.Comparer, t *testing.T) { + cb := func(t *testing.T) { + t.Parallel() + a := ds.RandomIntegers(length, length) + a = sort(a) + if !Sorted(a) { + t.Errorf("Array not sorted: %v", a) + } + } + t.Run(fmt.Sprintf("Test%s%d", name, length), cb) +} -- cgit v1.2.3