From f46af337023b0a722c55e560fc59221dcd93f153 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Fri, 4 Aug 2023 23:05:56 +0200 Subject: [PATCH] Added a new test case for text reader --- assets/trivial-bigger.txt | 5 +++ io/reader/text_test.go | 69 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 assets/trivial-bigger.txt diff --git a/assets/trivial-bigger.txt b/assets/trivial-bigger.txt new file mode 100644 index 0000000..97abccc --- /dev/null +++ b/assets/trivial-bigger.txt @@ -0,0 +1,5 @@ +### ### +### ### +# # +##### # +##### # diff --git a/io/reader/text_test.go b/io/reader/text_test.go index 7f031fc..4b77a2a 100644 --- a/io/reader/text_test.go +++ b/io/reader/text_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -func TestTextRead(t *testing.T) { +func TestTextReadTrivial(t *testing.T) { /* trivial.txt ## ## # # @@ -55,7 +55,72 @@ func TestTextRead(t *testing.T) { } for i, got := range got.Nodes { - fmt.Println(i) + expected := nodes[i] + + checkNode(t, i, got, expected, "") + checkNode(t, i, got.Left, expected.Left, "left") + checkNode(t, i, got.Right, expected.Right, "Right") + checkNode(t, i, got.Up, expected.Up, "Up") + checkNode(t, i, got.Down, expected.Down, "Down") + } +} + +func TestTextReadTrivialBigger(t *testing.T) { + /* trivial-bigger.txt + ### ### + ### ### + # # + ##### # + ##### # + + Nodes are + ###0### + ### ### + #1 2 3# + ##### # + #####4# + */ + nodes := make([]*maze.Node, 5) + + nodes[0] = maze.NewNode(maze.Coordinates{X: 3, Y: 0}) + + nodes[1] = maze.NewNode(maze.Coordinates{X: 1, Y: 2}) + nodes[2] = maze.NewNode(maze.Coordinates{X: 3, Y: 2}) + nodes[3] = maze.NewNode(maze.Coordinates{X: 5, Y: 2}) + + nodes[4] = maze.NewNode(maze.Coordinates{X: 5, Y: 4}) + + nodes[0].Down = nodes[2] + + nodes[1].Right = nodes[2] + + nodes[2].Up = nodes[0] + nodes[2].Left = nodes[1] + nodes[2].Right = nodes[3] + + nodes[3].Left = nodes[2] + nodes[3].Down = nodes[4] + + nodes[4].Up = nodes[3] + + reader := TextReader{ + PathChar: ' ', + WallChar: '#', + } + + filename := "../../assets/trivial-bigger.txt" + got, err := reader.Read(filename) + utils.Check(err, "Couldn't create maze from %q", filename) + + if len(nodes) != len(got.Nodes) { + t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes)) + } + + for _, node := range got.Nodes { + fmt.Println(node) + } + + for i, got := range got.Nodes { expected := nodes[i] checkNode(t, i, got, expected, "")