-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
57 lines (52 loc) · 1.53 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
_ "fmt"
"strings"
"testing"
)
type solverTest struct {
maze string
expected string
desc string
}
var solverTests = []solverTest{
solverTest{
desc: "Test case from problem statement PDF",
maze: `{"forward": "tiger", "left": {"forward": {"upstairs": "exit"}, "left": "dragon"}, "right": {"forward": "dead end"}}`,
expected: "left forward upstairs",
},
solverTest{
desc: "Test case from problem statement PDF",
maze: `{"forward": "exit"}`,
expected: "forward",
},
solverTest{
desc: "Test case from problem statement PDF",
maze: `{"forward": "tiger", "left": "ogre", "right": "demon"}`,
expected: "Sorry",
},
solverTest{
desc: "Check if the exit is the nearest exit.",
maze: `{"A": {"B": {"C": {"Z": "exit"}}}, "D": {"E": "exit"}, "F": {"G": {"H": "exit" }} , "I": "random stuff"}`,
expected: "D E",
},
solverTest{
desc: "Check if the exit is the nearest exit.",
maze: `{"A": {"B": {"C": {"Z": "exit"}}}, "D": {"E": "exit"}, "F": {"G": {"H": "exit" }} , "I": "exit"}`,
expected: "I",
},
}
func TestSolver(t *testing.T) {
var s Solver
for _, test := range solverTests {
output := s.SolveMazeVerbose(test.maze)
// Assertion is needed here because the function above could return different types
arr, isArr := output.([]string)
if isArr {
output = strings.Join(arr, " ")
}
if output != test.expected {
t.Errorf("Expected %q but got %q for maze %q. Test case description: %q", test.expected, output, test.maze, test.desc)
}
}
}