1 class TestCase {
2 public TestCase(string forward, string backward) {
3 forward_ = forward;
4 backward_ = backward;
5 }
6
7 public void execute() {
8
9
10
11
12
13
14
15
16
17
18
19
20
21 BoundsAction boundsAction = new BoundsAction();
22 Position position = new Position(0, 0, boundsAction);
23 Orientation.Direction endDirection = traverseMaze(position);
24
25
26 bool endIsEast = endDirection==Orientation.Direction.E;
27 bool endIsWest = endDirection==Orientation.Direction.W;
28 bool endIsSouth = endDirection==Orientation.Direction.S;
29
30
31 int numRows = boundsAction.numRows() - 1 - (endIsSouth?1:0);
32 int numCols = boundsAction.numCols() - (endIsEast || endIsWest ?1:0);
33
34
35 maze_ = new Maze(numRows, numCols);
36
37
38 OpenAction openAction = new OpenAction(maze_);
39
40
41 int startX = -boundsAction.minX() - (endIsWest?1:0);
42 int startY = numRows;
43 position = new Position(startX, startY, openAction);
44 traverseMaze(position);
45 }
46
47 private Orientation.Direction traverseMaze(Position position) {
48 Orientation orientation = new Orientation(Orientation.Direction.S);
49 Explorer explorer = new Explorer(orientation, position);
50 explorer.processInput(forward_);
51 Orientation.Direction endDirection = explorer.getOrientation().getDirection();
52 explorer.turnBackwards();
53 explorer.processInput(backward_);
54 return endDirection;
55 }
56
57
58 private string forward_;
59 private string backward_;
60 public Maze maze_ {get; private set;}
61 }
62