From 58787dc4afa3d50f54600016a91500a886e2d7f9 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Mon, 7 Aug 2023 18:18:25 +0200 Subject: [PATCH] moved assertEquals to utils so that other tests can use it --- io/reader/strings_test.go | 16 +++++----------- utils/utils.go | 8 ++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/io/reader/strings_test.go b/io/reader/strings_test.go index 4255555..a094c0e 100644 --- a/io/reader/strings_test.go +++ b/io/reader/strings_test.go @@ -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...) - } -} diff --git a/utils/utils.go b/utils/utils.go index 717c2e2..3ce6c66 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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...) + } +}