diff --git a/io/reader/text_test.go b/io/reader/text_test.go new file mode 100644 index 0000000..63343f4 --- /dev/null +++ b/io/reader/text_test.go @@ -0,0 +1,106 @@ +package reader + +import ( + "maze-solver/maze" + "maze-solver/utils" + "reflect" + "testing" +) + +func TestTextReadTrivial(t *testing.T) { + tests := []struct { + name string + filename string + pathChar byte + wallChar byte + expected *maze.RawMaze + }{ + { + "Trivial", + "../../assets/trivial.txt", + ' ', + '#', + &maze.RawMaze{ + PathChar: ' ', + WallChar: '#', + Data: []string{ + "## ##", + "# #", + "### #", + }, + }, + }, + { + "Trivial Bigger", + "../../assets/trivial-bigger.txt", + ' ', + '#', + &maze.RawMaze{ + PathChar: ' ', + WallChar: '#', + Data: []string{ + "### ###", + "### ###", + "# #", + "##### #", + "##### #", + }, + }, + }, + { + "Bigger Staggered", + "../../assets/trivial-bigger-staggered.txt", + ' ', + '#', + &maze.RawMaze{ + PathChar: ' ', + WallChar: '#', + Data: []string{ + "### ###", + "### ###", + "# #", + "#### ##", + "#### ##", + }, + }, + }, + { + "Normal", + "../../assets/normal.txt", + ' ', + '#', + &maze.RawMaze{ + PathChar: ' ', + WallChar: '#', + Data: []string{ + "##### #####", + "# # #", + "##### ### #", + "# # #", + "# # ##### #", + "# # #", + "### ### # #", + "# # # #", + "# ####### #", + "# # #", + "##### #####", + }, + }, + }, + } + + for _, test := range tests { + reader := TextReader{ + Filename: test.filename, + PathChar: test.pathChar, + WallChar: test.wallChar, + } + + got, err := reader.Read() + utils.Check(err, "Couldn't read file %q", reader.Filename) + + if !reflect.DeepEqual(got, test.expected) { + t.Fatalf("%s: lexed mazes do not match\nGot: %v\nWant: %v", test.name, got, test.expected) + } + } +}