2023-08-05 11:21:32 +02:00
|
|
|
package reader
|
|
|
|
|
|
|
|
import (
|
2023-08-07 18:09:58 +02:00
|
|
|
"maze-solver/utils"
|
|
|
|
"reflect"
|
2023-08-05 11:21:32 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTextReadTrivial(t *testing.T) {
|
2023-08-07 18:09:58 +02:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
filename string
|
|
|
|
pathChar byte
|
|
|
|
wallChar byte
|
|
|
|
expected *RawMaze
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"Trivial",
|
|
|
|
"../../assets/trivial.txt",
|
|
|
|
' ',
|
|
|
|
'#',
|
|
|
|
&RawMaze{
|
|
|
|
Width: 5,
|
|
|
|
Height: 3,
|
|
|
|
Data: [][]byte{
|
|
|
|
{0b_00100_000},
|
|
|
|
{0b_01110_000},
|
|
|
|
{0b_00010_000},
|
2023-08-05 11:21:32 +02:00
|
|
|
},
|
|
|
|
},
|
2023-08-07 18:09:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Trivial Bigger",
|
|
|
|
"../../assets/trivial-bigger.txt",
|
|
|
|
' ',
|
|
|
|
'#',
|
|
|
|
&RawMaze{
|
|
|
|
Width: 7,
|
|
|
|
Height: 5,
|
|
|
|
Data: [][]byte{
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0111110_0},
|
|
|
|
{0b_0000010_0},
|
|
|
|
{0b_0000010_0},
|
2023-08-05 11:21:32 +02:00
|
|
|
},
|
|
|
|
},
|
2023-08-07 18:09:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Bigger Staggered",
|
|
|
|
"../../assets/trivial-bigger-staggered.txt",
|
|
|
|
' ',
|
|
|
|
'#',
|
|
|
|
&RawMaze{
|
|
|
|
Width: 7,
|
|
|
|
Height: 5,
|
|
|
|
Data: [][]byte{
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0001000_0},
|
|
|
|
{0b_0111110_0},
|
|
|
|
{0b_0000100_0},
|
|
|
|
{0b_0000100_0},
|
2023-08-05 11:21:32 +02:00
|
|
|
},
|
|
|
|
},
|
2023-08-07 18:09:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Normal",
|
|
|
|
"../../assets/normal.txt",
|
|
|
|
' ',
|
|
|
|
'#',
|
|
|
|
&RawMaze{
|
|
|
|
Width: 11,
|
|
|
|
Height: 11,
|
|
|
|
Data: [][]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 11:21:32 +02:00
|
|
|
},
|
|
|
|
},
|
2023-08-07 18:09:58 +02:00
|
|
|
},
|
|
|
|
}
|
2023-08-05 11:21:32 +02:00
|
|
|
|
2023-08-07 18:09:58 +02:00
|
|
|
for _, test := range tests {
|
|
|
|
reader := TextReader{
|
|
|
|
Filename: test.filename,
|
|
|
|
PathChar: test.pathChar,
|
|
|
|
WallChar: test.wallChar,
|
|
|
|
}
|
2023-08-05 16:18:03 +02:00
|
|
|
|
2023-08-07 18:09:58 +02:00
|
|
|
got, err := reader.Read()
|
|
|
|
utils.Check(err, "Couldn't read file %q", reader.Filename)
|
2023-08-05 11:21:32 +02:00
|
|
|
|
2023-08-07 18:09:58 +02:00
|
|
|
if !reflect.DeepEqual(got, test.expected) {
|
|
|
|
t.Fatalf("%s: lexed mazes do not match\nGot: %v\nWant: %v", test.name, got, test.expected)
|
2023-08-05 11:21:32 +02:00
|
|
|
}
|
2023-08-07 18:09:58 +02:00
|
|
|
}
|
2023-08-05 11:21:32 +02:00
|
|
|
}
|