From f76b0855b85943cee35002757ae91de32fbc8431 Mon Sep 17 00:00:00 2001 From: Charles Clinton Pustejovsky III Date: Fri, 22 Sep 2023 14:01:36 -0400 Subject: [PATCH] feat: update pure_test.go to not use testify change test names to accurately reflect function names --- pure/pure_test.go | 97 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/pure/pure_test.go b/pure/pure_test.go index d17832a..ef74bc2 100644 --- a/pure/pure_test.go +++ b/pure/pure_test.go @@ -2,54 +2,113 @@ package pure_test import ( "github.com/cpustejovsky/customsortgo/pure" - "github.com/stretchr/testify/assert" "testing" ) -func TestSortForStrings(t *testing.T) { +func TestNewSortForStrings(t *testing.T) { w := []string{"cat", "albatross", "dolphin", "bee", "zebra", "aardvark"} want := []string{"aardvark", "albatross", "bee", "cat", "dolphin", "zebra"} got := pure.NewSortedStrings(w) - assert.Equal(t, want, got) - assert.NotEqual(t, got, w) + if !equalStringSlices(want, got) { + t.Errorf("got:\n%v\nwanted:\n%v\n", got, want) + } + if equalStringSlices(w, got) { + t.Errorf("orignal:\n%v\n and output:\n%v\nshould not be equal\n", w, got) + } } -func TestReverseSortForStrings(t *testing.T) { +func TestNewReverseSortForStrings(t *testing.T) { w := []string{"cat", "albatross", "dolphin", "bee", "zebra", "aardvark"} want := []string{"zebra", "dolphin", "cat", "bee", "albatross", "aardvark"} got := pure.NewReverseSortedStrings(w) - assert.Equal(t, want, got) - assert.NotEqual(t, got, w) + if !equalStringSlices(want, got) { + t.Errorf("got:\n%v\nwanted:\n%v\n", got, want) + } + if equalStringSlices(w, got) { + t.Errorf("orignal:\n%v\n and output:\n%v\nshould not be equal\n", w, got) + } } -func TestSortInts(t *testing.T) { +func TestNewSortInts(t *testing.T) { n := []int{1, 3, 5, 2, 7, 6, 4} want := []int{1, 2, 3, 4, 5, 6, 7} got := pure.NewSortedIntegers(n) - assert.Equal(t, want, got) - assert.NotEqual(t, got, n) + if !equalIntSlices(want, got) { + t.Errorf("got:\n%v\nwanted:\n%v\n", got, want) + } + if equalIntSlices(n, got) { + t.Errorf("orignal:\n%v\n and output:\n%v\nshould not be equal\n", n, got) + } } -func TestReverseSortInts(t *testing.T) { +func TestNewReverseSortInts(t *testing.T) { n := []int{1, 3, 5, 2, 7, 6, 4} want := []int{7, 6, 5, 4, 3, 2, 1} got := pure.NewReverseSortedIntegers(n) - assert.Equal(t, want, got) - assert.NotEqual(t, got, n) + if !equalIntSlices(want, got) { + t.Errorf("got:\n%v\nwanted:\n%v\n", got, want) + } + if equalIntSlices(n, got) { + t.Errorf("orignal:\n%v\n and output:\n%v\nshould not be equal\n", n, got) + } } -func TestSortFloat64s(t *testing.T) { +func TestNewSortFloat64s(t *testing.T) { n := []float64{1.1, 3.3, 5.5, 2.2, 7.7, 6.6, 4.4} want := []float64{1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7} got := pure.NewSortedFloats(n) - assert.Equal(t, want, got) - assert.NotEqual(t, got, n) + if !equalFloatSlices(want, got) { + t.Errorf("got:\n%v\nwanted:\n%v\n", got, want) + } + if equalFloatSlices(n, got) { + t.Errorf("orignal:\n%v\n and output:\n%v\nshould not be equal\n", n, got) + } } -func TestReverseSortFloat64s(t *testing.T) { +func TestNewReverseSortFloat64s(t *testing.T) { n := []float64{1.1, 3.3, 5.5, 2.2, 7.7, 6.6, 4.4} want := []float64{7.7, 6.6, 5.5, 4.4, 3.3, 2.2, 1.1} got := pure.NewReverseSortedFloats(n) - assert.Equal(t, want, got) - assert.NotEqual(t, got, n) + if !equalFloatSlices(want, got) { + t.Errorf("got:\n%v\nwanted:\n%v\n", got, want) + } + if equalFloatSlices(n, got) { + t.Errorf("orignal:\n%v\n and output:\n%v\nshould not be equal\n", n, got) + } +} + +func equalStringSlices(a, b []string) bool { + if len(a) != len(b) { + return false + } + for i, s := range a { + if s != b[i] { + return false + } + } + return true +} + +func equalIntSlices(a, b []int) bool { + if len(a) != len(b) { + return false + } + for i, s := range a { + if s != b[i] { + return false + } + } + return true +} + +func equalFloatSlices(a, b []float64) bool { + if len(a) != len(b) { + return false + } + for i, s := range a { + if s != b[i] { + return false + } + } + return true }