moved assertEquals to utils so that other tests

can use it
This commit is contained in:
Karma Riuk 2023-08-07 18:18:25 +02:00
parent 36051b06f6
commit 6b045e25e0
2 changed files with 13 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package reader
import (
"maze-solver/utils"
"testing"
)
@ -111,13 +112,13 @@ func TestStringsReader(t *testing.T) {
}
got, _ := reader.Read()
assertEqual(t, got.Width, test.width, "%s: width of raw maze don't match", test.name)
assertEqual(t, got.Height, test.height, "%s: height of raw maze don't match", test.name)
assertEqual(t, len(got.Data), len(test.expected), "%s: don't have the same number of rows", test.name)
utils.AssertEqual(t, got.Width, test.width, "%s: width of raw maze don't match", test.name)
utils.AssertEqual(t, got.Height, test.height, "%s: height of raw maze don't match", test.name)
utils.AssertEqual(t, len(got.Data), len(test.expected), "%s: don't have the same number of rows", test.name)
for y, line_exp := range test.expected {
line_got := got.Data[y]
assertEqual(t, len(line_got), len(line_exp), "%s (line %v): don't have same number of chunks, %v, want %v", test.name, y)
utils.AssertEqual(t, len(line_got), len(line_exp), "%s (line %v): don't have same number of chunks, %v, want %v", test.name, y)
for i, chunk_exp := range line_exp {
chunk_got := line_got[i]
@ -128,10 +129,3 @@ func TestStringsReader(t *testing.T) {
}
}
}
func assertEqual[T comparable](t *testing.T, got T, want T, msg string, args ...any) {
args = append(args, got, want)
if got != want {
t.Fatalf(msg+"\nGot: %v, Want: %v", args...)
}
}

View File

@ -2,6 +2,7 @@ package utils
import (
"log"
"testing"
"golang.org/x/exp/constraints"
)
@ -19,3 +20,10 @@ func Min[T constraints.Ordered](a, b T) T {
}
return b
}
func AssertEqual[T comparable](t *testing.T, got T, want T, msg string, args ...any) {
args = append(args, got, want)
if got != want {
t.Fatalf(msg+"\nGot: %v, Want: %v", args...)
}
}