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:
parent
58787dc4af
commit
92ba1b48e4
@ -20,7 +20,7 @@ func NewNode(coords Coordinates) *Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Maze struct {
|
type Maze struct {
|
||||||
Width, Height uint
|
Width, Height int
|
||||||
Nodes []*Node
|
Nodes []*Node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,13 +8,18 @@ import (
|
|||||||
|
|
||||||
func Parse(reader reader.Reader) (*maze.Maze, error) {
|
func Parse(reader reader.Reader) (*maze.Maze, error) {
|
||||||
nodesByCoord := make(map[maze.Coordinates]*maze.Node)
|
nodesByCoord := make(map[maze.Coordinates]*maze.Node)
|
||||||
ret := &maze.Maze{}
|
|
||||||
|
|
||||||
raw_maze, err := reader.Read()
|
raw_maze, err := reader.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret := &maze.Maze{
|
||||||
|
Width: raw_maze.Width,
|
||||||
|
Height: raw_maze.Height,
|
||||||
|
Nodes: []*maze.Node{},
|
||||||
|
}
|
||||||
|
|
||||||
y := 0
|
y := 0
|
||||||
// Parse first line to get entrance
|
// Parse first line to get entrance
|
||||||
for x := 0; x < raw_maze.Width-1; x++ {
|
for x := 0; x < raw_maze.Width-1; x++ {
|
||||||
|
@ -51,6 +51,9 @@ func TestTextReadTrivial(t *testing.T) {
|
|||||||
got, err := Parse(reader)
|
got, err := Parse(reader)
|
||||||
utils.Check(err, "Couldn't create maze from %q", reader.Filename)
|
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) {
|
if len(nodes) != len(got.Nodes) {
|
||||||
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(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)
|
got, err := Parse(reader)
|
||||||
utils.Check(err, "Couldn't create maze from %q", reader.Filename)
|
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) {
|
if len(nodes) != len(got.Nodes) {
|
||||||
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(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)
|
got, err := Parse(reader)
|
||||||
utils.Check(err, "Couldn't create maze from %q", reader.Filename)
|
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) {
|
if len(nodes) != len(got.Nodes) {
|
||||||
t.Fatalf("Didn't get the same size of nodes: %v, want %v", len(got.Nodes), len(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)
|
got, err := Parse(reader)
|
||||||
utils.Check(err, "Couldn't create maze from %q", reader.Filename)
|
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) {
|
if len(nodes) != len(got.Nodes) {
|
||||||
for i, node := range got.Nodes {
|
for i, node := range got.Nodes {
|
||||||
fmt.Printf("%v: %v\n", i, node)
|
fmt.Printf("%v: %v\n", i, node)
|
||||||
|
Loading…
Reference in New Issue
Block a user