Forgot to put the width and height of the maze

when I parsed it, oops (and now it's tested)
This commit is contained in:
Karma Riuk 2023-08-07 18:22:04 +02:00
parent 6b045e25e0
commit 104419b239
3 changed files with 19 additions and 2 deletions

View File

@ -20,7 +20,7 @@ func NewNode(coords Coordinates) *Node {
}
type Maze struct {
Width, Height uint
Width, Height int
Nodes []*Node
}

View File

@ -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++ {

View File

@ -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)