Added a new test case for text reader
This commit is contained in:
parent
7c7c2d04d4
commit
dbcaf137ef
5
assets/trivial-bigger.txt
Normal file
5
assets/trivial-bigger.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
### ###
|
||||||
|
### ###
|
||||||
|
# #
|
||||||
|
##### #
|
||||||
|
##### #
|
@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTextRead(t *testing.T) {
|
func TestTextReadTrivial(t *testing.T) {
|
||||||
/* trivial.txt
|
/* trivial.txt
|
||||||
## ##
|
## ##
|
||||||
# #
|
# #
|
||||||
@ -55,7 +55,72 @@ func TestTextRead(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, got := range got.Nodes {
|
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]
|
expected := nodes[i]
|
||||||
|
|
||||||
checkNode(t, i, got, expected, "")
|
checkNode(t, i, got, expected, "")
|
||||||
|
Loading…
Reference in New Issue
Block a user