From 104419b239687b01ba7b135f79b48c3a64d16b15 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Mon, 7 Aug 2023 18:22:04 +0200 Subject: [PATCH] Forgot to put the width and height of the maze when I parsed it, oops (and now it's tested) --- maze/maze.go | 2 +- maze/parser/parser.go | 7 ++++++- maze/parser/parser_test.go | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/maze/maze.go b/maze/maze.go index 471e361..997597c 100644 --- a/maze/maze.go +++ b/maze/maze.go @@ -20,7 +20,7 @@ func NewNode(coords Coordinates) *Node { } type Maze struct { - Width, Height uint + Width, Height int Nodes []*Node } diff --git a/maze/parser/parser.go b/maze/parser/parser.go index b0cd915..7ea83a1 100644 --- a/maze/parser/parser.go +++ b/maze/parser/parser.go @@ -8,13 +8,18 @@ import ( func Parse(reader reader.Reader) (*maze.Maze, error) { nodesByCoord := make(map[maze.Coordinates]*maze.Node) - ret := &maze.Maze{} raw_maze, err := reader.Read() if err != nil { return nil, err } + ret := &maze.Maze{ + Width: raw_maze.Width, + Height: raw_maze.Height, + Nodes: []*maze.Node{}, + } + y := 0 // Parse first line to get entrance for x := 0; x < raw_maze.Width-1; x++ { diff --git a/maze/parser/parser_test.go b/maze/parser/parser_test.go index 61560c9..6c42d90 100644 --- a/maze/parser/parser_test.go +++ b/maze/parser/parser_test.go @@ -51,6 +51,9 @@ func TestTextReadTrivial(t *testing.T) { got, err := Parse(reader) utils.Check(err, "Couldn't create maze from %q", reader.Filename) + utils.AssertEqual(t, got.Width, 5, "Normal: width differ") + utils.AssertEqual(t, got.Height, 3, "Normal: height differ") + if len(nodes) != len(got.Nodes) { t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes)) } @@ -113,6 +116,9 @@ func TestTextReadTrivialBigger(t *testing.T) { got, err := Parse(reader) utils.Check(err, "Couldn't create maze from %q", reader.Filename) + utils.AssertEqual(t, got.Width, 7, "Normal: width differ") + utils.AssertEqual(t, got.Height, 5, "Normal: height differ") + if len(nodes) != len(got.Nodes) { t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes)) } @@ -180,6 +186,9 @@ func TestTextReadTrivialBiggerStaggered(t *testing.T) { got, err := Parse(reader) utils.Check(err, "Couldn't create maze from %q", reader.Filename) + utils.AssertEqual(t, got.Width, 7, "Normal: width differ") + utils.AssertEqual(t, got.Height, 5, "Normal: height differ") + if len(nodes) != len(got.Nodes) { t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(nodes)) } @@ -334,6 +343,9 @@ func TestTextReadNormal(t *testing.T) { got, err := Parse(reader) utils.Check(err, "Couldn't create maze from %q", reader.Filename) + utils.AssertEqual(t, got.Width, 11, "Normal: width differ") + utils.AssertEqual(t, got.Height, 11, "Normal: height differ") + if len(nodes) != len(got.Nodes) { for i, node := range got.Nodes { fmt.Printf("%v: %v\n", i, node)