maze-solver-go/io/reader/strings_test.go
2023-08-07 18:18:25 +02:00

132 lines
2.5 KiB
Go

package reader
import (
"maze-solver/utils"
"testing"
)
func TestStringsReader(t *testing.T) {
tests := []struct {
name string
width, height int
pathChar byte
wallChar byte
lines []string
expected [][]byte
}{
{
"Trivial",
5, 3,
' ',
'#',
[]string{
"## ##",
"# #",
"### #",
},
[][]byte{
{0b_00100_000},
{0b_01110_000},
{0b_00010_000},
},
},
{
"Trivial Bigger",
7, 5,
' ',
'#',
[]string{
"### ###",
"### ###",
"# #",
"##### #",
"##### #",
},
[][]byte{
{0b_0001000_0},
{0b_0001000_0},
{0b_0111110_0},
{0b_0000010_0},
{0b_0000010_0},
},
},
{
"Bigger Staggered",
7, 5,
' ',
'#',
[]string{
"### ###",
"### ###",
"# #",
"#### ##",
"#### ##",
},
[][]byte{
{0b_0001000_0},
{0b_0001000_0},
{0b_0111110_0},
{0b_0000100_0},
{0b_0000100_0},
},
},
{
"Normal",
11, 11,
' ',
'#',
[]string{
"##### #####",
"# # #",
"##### ### #",
"# # #",
"# # ##### #",
"# # #",
"### ### # #",
"# # # #",
"# ####### #",
"# # #",
"##### #####",
},
[][]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},
},
},
}
for _, test := range tests {
reader := StringsReader{
PathChar: test.pathChar,
WallChar: test.wallChar,
Lines: &test.lines,
}
got, _ := reader.Read()
utils.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)
utils.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 {
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)
for i, chunk_exp := range line_exp {
chunk_got := line_got[i]
if chunk_got != chunk_exp {
t.Fatalf("%s (line %v): chunk %v don't coincide, %08b, want %08b", test.name, y, i, chunk_got, chunk_exp)
}
}
}
}
}