2023-08-05 16:36:49 +02:00
|
|
|
package reader
|
2023-08-05 12:02:42 +02:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestRawMazeWall(t *testing.T) {
|
|
|
|
tests := []struct {
|
2023-08-05 16:36:49 +02:00
|
|
|
name string
|
|
|
|
width, height int
|
|
|
|
pathChar, wallChar byte
|
|
|
|
data []string
|
|
|
|
expected [][]bool
|
2023-08-05 12:02:42 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Trivial",
|
2023-08-05 16:18:03 +02:00
|
|
|
5, 3,
|
2023-08-05 16:36:49 +02:00
|
|
|
' ', '#',
|
|
|
|
[]string{
|
|
|
|
"## ##",
|
|
|
|
"# #",
|
|
|
|
"### #",
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{true, true, false, true, true},
|
|
|
|
{true, false, false, false, true},
|
|
|
|
{true, true, true, false, true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Trivial Bigger",
|
2023-08-05 16:18:03 +02:00
|
|
|
7, 5,
|
2023-08-05 16:36:49 +02:00
|
|
|
' ', '#',
|
|
|
|
[]string{
|
|
|
|
"### ###",
|
|
|
|
"### ###",
|
|
|
|
"# #",
|
|
|
|
"##### #",
|
|
|
|
"##### #",
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{true, true, true, false, true, true, true},
|
|
|
|
{true, true, true, false, true, true, true},
|
|
|
|
{true, false, false, false, false, false, true},
|
|
|
|
{true, true, true, true, true, false, true},
|
|
|
|
{true, true, true, true, true, false, true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Bigger Staggered",
|
2023-08-05 16:18:03 +02:00
|
|
|
7, 5,
|
2023-08-05 16:36:49 +02:00
|
|
|
' ', '#',
|
|
|
|
[]string{
|
|
|
|
"### ###",
|
|
|
|
"### ###",
|
|
|
|
"# #",
|
|
|
|
"#### ##",
|
|
|
|
"#### ##",
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{true, true, true, false, true, true, true},
|
|
|
|
{true, true, true, false, true, true, true},
|
|
|
|
{true, false, false, false, false, false, true},
|
|
|
|
{true, true, true, true, false, true, true},
|
|
|
|
{true, true, true, true, false, true, true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Normal",
|
2023-08-05 16:18:03 +02:00
|
|
|
11, 11,
|
2023-08-05 16:36:49 +02:00
|
|
|
' ', '#',
|
|
|
|
[]string{
|
|
|
|
"##### #####",
|
|
|
|
"# # #",
|
|
|
|
"##### ### #",
|
|
|
|
"# # #",
|
|
|
|
"# # ##### #",
|
|
|
|
"# # #",
|
|
|
|
"### ### # #",
|
|
|
|
"# # # #",
|
|
|
|
"# ####### #",
|
|
|
|
"# # #",
|
|
|
|
"##### #####",
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{true, true, true, true, true, false, true, true, true, true, true},
|
|
|
|
{true, false, false, false, false, false, true, false, false, false, true},
|
|
|
|
{true, true, true, true, true, false, true, true, true, false, true},
|
|
|
|
{true, false, false, false, true, false, false, false, false, false, true},
|
|
|
|
{true, false, true, false, true, true, true, true, true, false, true},
|
|
|
|
{true, false, true, false, false, false, false, false, false, false, true},
|
|
|
|
{true, true, true, false, true, true, true, false, true, false, true},
|
|
|
|
{true, false, false, false, true, false, false, false, true, false, true},
|
|
|
|
{true, false, true, true, true, true, true, true, true, false, true},
|
|
|
|
{true, false, false, false, false, false, true, false, false, false, true},
|
|
|
|
{true, true, true, true, true, false, true, true, true, true, true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2023-08-05 16:36:49 +02:00
|
|
|
reader := StringsReader{
|
|
|
|
PathChar: test.pathChar,
|
|
|
|
WallChar: test.wallChar,
|
|
|
|
Lines: &test.data,
|
2023-08-05 12:02:42 +02:00
|
|
|
}
|
2023-08-05 16:36:49 +02:00
|
|
|
rawMaze, _ := reader.Read()
|
2023-08-05 12:02:42 +02:00
|
|
|
for y, row := range test.expected {
|
|
|
|
for x, expected := range row {
|
2023-08-05 16:18:03 +02:00
|
|
|
if rawMaze.IsWall(x, y) != expected {
|
|
|
|
t.Fatalf("%s: Wanted wall at (%v, %v), apparently it isn't", test.name, x, y)
|
2023-08-05 12:02:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRawMazePath(t *testing.T) {
|
|
|
|
tests := []struct {
|
2023-08-05 16:18:03 +02:00
|
|
|
name string
|
|
|
|
width, height int
|
|
|
|
data [][]byte
|
|
|
|
expected [][]bool
|
2023-08-05 12:02:42 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Trivial",
|
2023-08-05 16:18:03 +02:00
|
|
|
5, 3,
|
|
|
|
[][]byte{
|
|
|
|
{0b_00100_000},
|
|
|
|
{0b_01110_000},
|
|
|
|
{0b_00010_000},
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{false, false, true, false, false},
|
|
|
|
{false, true, true, true, false},
|
|
|
|
{false, false, false, true, false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Trivial Bigger",
|
2023-08-05 16:18:03 +02:00
|
|
|
7, 5,
|
|
|
|
[][]byte{
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0111110_0},
|
|
|
|
{0b_0000010_0},
|
|
|
|
{0b_0000010_0},
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{false, false, false, true, false, false, false},
|
|
|
|
{false, false, false, true, false, false, false},
|
|
|
|
{false, true, true, true, true, true, false},
|
|
|
|
{false, false, false, false, false, true, false},
|
|
|
|
{false, false, false, false, false, true, false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Bigger Staggered",
|
2023-08-05 16:18:03 +02:00
|
|
|
7, 5,
|
|
|
|
[][]byte{
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0111110_0},
|
|
|
|
{0b_0000100_0},
|
|
|
|
{0b_0000100_0},
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{false, false, false, true, false, false, false},
|
|
|
|
{false, false, false, true, false, false, false},
|
|
|
|
{false, true, true, true, true, true, false},
|
|
|
|
{false, false, false, false, true, false, false},
|
|
|
|
{false, false, false, false, true, false, false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Normal",
|
2023-08-05 16:18:03 +02:00
|
|
|
11, 11,
|
|
|
|
[][]byte{
|
|
|
|
{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},
|
2023-08-05 12:02:42 +02:00
|
|
|
},
|
|
|
|
[][]bool{
|
|
|
|
{false, false, false, false, false, true, false, false, false, false, false},
|
|
|
|
{false, true, true, true, true, true, false, true, true, true, false},
|
|
|
|
{false, false, false, false, false, true, false, false, false, true, false},
|
|
|
|
{false, true, true, true, false, true, true, true, true, true, false},
|
|
|
|
{false, true, false, true, false, false, false, false, false, true, false},
|
|
|
|
{false, true, false, true, true, true, true, true, true, true, false},
|
|
|
|
{false, false, false, true, false, false, false, true, false, true, false},
|
|
|
|
{false, true, true, true, false, true, true, true, false, true, false},
|
|
|
|
{false, true, false, false, false, false, false, false, false, true, false},
|
|
|
|
{false, true, true, true, true, true, false, true, true, true, false},
|
|
|
|
{false, false, false, false, false, true, false, false, false, false, false},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
rawMaze := RawMaze{
|
2023-08-05 16:18:03 +02:00
|
|
|
Width: test.width,
|
|
|
|
Height: test.height,
|
|
|
|
Data: test.data,
|
2023-08-05 12:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for y, row := range test.expected {
|
|
|
|
for x, expected := range row {
|
2023-08-05 16:18:03 +02:00
|
|
|
if rawMaze.IsPath(x, y) != expected {
|
|
|
|
t.Fatalf("%s: Wanted path at (%v, %v), apparently it isn't", test.name, x, y)
|
2023-08-05 12:02:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|