Skip to content

Commit

Permalink
feat: update pure_test.go to not use testify
Browse files Browse the repository at this point in the history
change test names to accurately reflect function names
  • Loading branch information
cpustejovsky committed Sep 22, 2023
1 parent 3dd7230 commit f76b085
Showing 1 changed file with 78 additions and 19 deletions.
97 changes: 78 additions & 19 deletions pure/pure_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f76b085

Please sign in to comment.