Compare commits
No commits in common. "92ba1b48e4876275e9fe6fc62937c96c40054fd4" and "b6dff509f9341c0acb2f722b844cd7380a702b5d" have entirely different histories.
92ba1b48e4
...
b6dff509f9
@ -1,7 +1,6 @@
|
|||||||
package reader
|
package reader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"maze-solver/utils"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -112,13 +111,13 @@ func TestStringsReader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
got, _ := reader.Read()
|
got, _ := reader.Read()
|
||||||
|
|
||||||
utils.AssertEqual(t, got.Width, test.width, "%s: width of raw maze don't match", test.name)
|
assertEqual(t, got.Width, test.width, "%s: width of raw maze don't match", test.name)
|
||||||
utils.AssertEqual(t, got.Height, test.height, "%s: height of raw maze don't match", test.name)
|
assertEqual(t, got.Height, test.height, "%s: height of raw maze don't match", test.name)
|
||||||
utils.AssertEqual(t, len(got.Data), len(test.expected), "%s: don't have the same number of rows", test.name)
|
assertEqual(t, len(got.Data), len(test.expected), "%s: don't have the same number of rows", test.name)
|
||||||
|
|
||||||
for y, line_exp := range test.expected {
|
for y, line_exp := range test.expected {
|
||||||
line_got := got.Data[y]
|
line_got := got.Data[y]
|
||||||
utils.AssertEqual(t, len(line_got), len(line_exp), "%s (line %v): don't have same number of chunks, %v, want %v", test.name, y)
|
assertEqual(t, len(line_got), len(line_exp), "%s (line %v): don't have same number of chunks, %v, want %v", test.name, y)
|
||||||
|
|
||||||
for i, chunk_exp := range line_exp {
|
for i, chunk_exp := range line_exp {
|
||||||
chunk_got := line_got[i]
|
chunk_got := line_got[i]
|
||||||
@ -129,3 +128,10 @@ func TestStringsReader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertEqual[T comparable](t *testing.T, got T, want T, msg string, args ...any) {
|
||||||
|
args = append(args, got, want)
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf(msg+"\nGot: %v, Want: %v", args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,31 +1,33 @@
|
|||||||
package reader
|
package reader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"maze-solver/utils"
|
// "maze-solver/maze"
|
||||||
"reflect"
|
// "maze-solver/utils"
|
||||||
|
// "reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTextReadTrivial(t *testing.T) {
|
func TestTextReadTrivial(t *testing.T) {
|
||||||
|
/*
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filename string
|
filename string
|
||||||
pathChar byte
|
pathChar byte
|
||||||
wallChar byte
|
wallChar byte
|
||||||
expected *RawMaze
|
expected *maze.RawMaze
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"Trivial",
|
"Trivial",
|
||||||
"../../assets/trivial.txt",
|
"../../assets/trivial.txt",
|
||||||
' ',
|
' ',
|
||||||
'#',
|
'#',
|
||||||
&RawMaze{
|
&maze.RawMaze{
|
||||||
Width: 5,
|
PathChar: ' ',
|
||||||
Height: 3,
|
WallChar: '#',
|
||||||
Data: [][]byte{
|
Data: []string{
|
||||||
{0b_00100_000},
|
"## ##",
|
||||||
{0b_01110_000},
|
"# #",
|
||||||
{0b_00010_000},
|
"### #",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -34,15 +36,15 @@ func TestTextReadTrivial(t *testing.T) {
|
|||||||
"../../assets/trivial-bigger.txt",
|
"../../assets/trivial-bigger.txt",
|
||||||
' ',
|
' ',
|
||||||
'#',
|
'#',
|
||||||
&RawMaze{
|
&maze.RawMaze{
|
||||||
Width: 7,
|
PathChar: ' ',
|
||||||
Height: 5,
|
WallChar: '#',
|
||||||
Data: [][]byte{
|
Data: []string{
|
||||||
{0b_0001000_0},
|
"### ###",
|
||||||
{0b_0001000_0},
|
"### ###",
|
||||||
{0b_0111110_0},
|
"# #",
|
||||||
{0b_0000010_0},
|
"##### #",
|
||||||
{0b_0000010_0},
|
"##### #",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -51,15 +53,15 @@ func TestTextReadTrivial(t *testing.T) {
|
|||||||
"../../assets/trivial-bigger-staggered.txt",
|
"../../assets/trivial-bigger-staggered.txt",
|
||||||
' ',
|
' ',
|
||||||
'#',
|
'#',
|
||||||
&RawMaze{
|
&maze.RawMaze{
|
||||||
Width: 7,
|
PathChar: ' ',
|
||||||
Height: 5,
|
WallChar: '#',
|
||||||
Data: [][]byte{
|
Data: []string{
|
||||||
{0b_0001000_0},
|
"### ###",
|
||||||
{0b_0001000_0},
|
"### ###",
|
||||||
{0b_0111110_0},
|
"# #",
|
||||||
{0b_0000100_0},
|
"#### ##",
|
||||||
{0b_0000100_0},
|
"#### ##",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -68,21 +70,21 @@ func TestTextReadTrivial(t *testing.T) {
|
|||||||
"../../assets/normal.txt",
|
"../../assets/normal.txt",
|
||||||
' ',
|
' ',
|
||||||
'#',
|
'#',
|
||||||
&RawMaze{
|
&maze.RawMaze{
|
||||||
Width: 11,
|
PathChar: ' ',
|
||||||
Height: 11,
|
WallChar: '#',
|
||||||
Data: [][]byte{
|
Data: []string{
|
||||||
{0b_00000100, 0b000_00000},
|
"##### #####",
|
||||||
{0b_01111101, 0b110_00000},
|
"# # #",
|
||||||
{0b_00000100, 0b010_00000},
|
"##### ### #",
|
||||||
{0b_01110111, 0b110_00000},
|
"# # #",
|
||||||
{0b_01010000, 0b010_00000},
|
"# # ##### #",
|
||||||
{0b_01011111, 0b110_00000},
|
"# # #",
|
||||||
{0b_00010001, 0b010_00000},
|
"### ### # #",
|
||||||
{0b_01110111, 0b010_00000},
|
"# # # #",
|
||||||
{0b_01000000, 0b010_00000},
|
"# ####### #",
|
||||||
{0b_01111101, 0b110_00000},
|
"# # #",
|
||||||
{0b_00000100, 0b000_00000},
|
"##### #####",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -102,4 +104,5 @@ func TestTextReadTrivial(t *testing.T) {
|
|||||||
t.Fatalf("%s: lexed mazes do not match\nGot: %v\nWant: %v", test.name, got, test.expected)
|
t.Fatalf("%s: lexed mazes do not match\nGot: %v\nWant: %v", test.name, got, test.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func NewNode(coords Coordinates) *Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Maze struct {
|
type Maze struct {
|
||||||
Width, Height int
|
Width, Height uint
|
||||||
Nodes []*Node
|
Nodes []*Node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,18 +8,13 @@ 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,9 +51,6 @@ 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))
|
||||||
}
|
}
|
||||||
@ -116,9 +113,6 @@ 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))
|
||||||
}
|
}
|
||||||
@ -186,9 +180,6 @@ 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))
|
||||||
}
|
}
|
||||||
@ -343,9 +334,6 @@ 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)
|
||||||
|
@ -2,7 +2,6 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
)
|
)
|
||||||
@ -20,10 +19,3 @@ func Min[T constraints.Ordered](a, b T) T {
|
|||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssertEqual[T comparable](t *testing.T, got T, want T, msg string, args ...any) {
|
|
||||||
args = append(args, got, want)
|
|
||||||
if got != want {
|
|
||||||
t.Fatalf(msg+"\nGot: %v, Want: %v", args...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user