Skip to content

Commit

Permalink
test: use testify assert on all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehoehns committed Nov 20, 2023
1 parent fae2fa4 commit 7c76377
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
11 changes: 3 additions & 8 deletions utils/files/filereader_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package files

import (
"reflect"
"github.com/stretchr/testify/assert"
"testing"
)

Expand All @@ -12,10 +12,7 @@ func TestReadLines(t *testing.T) {
expected := []string{"this", "is", "a", "test", "file"}
actual := ReadLines("./input.txt")

if !reflect.DeepEqual(expected, actual) {
t.Errorf("Expected %s but actual was %s", expected, actual)
}

assert.Equal(t, expected, actual)
})

}
Expand All @@ -25,8 +22,6 @@ func TestRead(t *testing.T) {
expected := "this\nis\na\ntest\nfile"
actual := Read("./input.txt")

if expected != actual {
t.Errorf("Expected %s but actual was %s", expected, actual)
}
assert.Equal(t, expected, actual)
})
}
22 changes: 7 additions & 15 deletions utils/ints/ints_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package ints

import "testing"
import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestSumList(t *testing.T) {

t.Run("Should total all values in a list of ints", func(t *testing.T) {
expected := 6
actual := Sum([]int{1, 2, 3})
if expected != actual {
t.Fail()
t.Logf("Expected %d but actual was %d", expected, actual)
}
assert.Equal(t, expected, actual)
})

}
Expand All @@ -20,18 +20,10 @@ func TestFromString(t *testing.T) {
t.Run("Should convert string to int", func(t *testing.T) {
expected := 2113
actual := FromString("2113")
if expected != actual {
t.Errorf("Expected %d but actual was %d", expected, actual)
}
assert.Equal(t, expected, actual)
})

t.Run("Should panic if provide a string that cannot be turned into an int", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected code to panic")
}
}()

FromString("test")
assert.Panics(t, func() { FromString("test") })
})
}
9 changes: 5 additions & 4 deletions utils/strings/strings_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package strings

import "testing"
import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestHasAllUniqueRunes(t *testing.T) {
type args struct {
Expand Down Expand Up @@ -39,9 +42,7 @@ func TestHasAllUniqueRunes(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HasAllUniqueRunes(tt.args.input); got != tt.want {
t.Errorf("HasAllUniqueRunes() = %v, want %v", got, tt.want)
}
assert.Equal(t, tt.want, HasAllUniqueRunes(tt.args.input))
})
}
}

0 comments on commit 7c76377

Please sign in to comment.