-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
158 lines (116 loc) · 3.88 KB
/
main.cpp
File metadata and controls
158 lines (116 loc) · 3.88 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// main.cpp
// Test functions for Maze and Creature classes
// Authors: Yusuf Pisan & Juan Arias
#include <string>
#include "creature.h"
// Global constants for easier change of file names
const char FILE1[] {"maze1.txt"};
const char FILE2[] {"maze2.txt"};
// Prints info of location of row and column in given Maze
void PrintLocationInfo(const Maze& maze, int row, int col) {
std::cout << maze << std::endl << std::boolalpha
<< "[" << row << ", " << col << "]" << std::endl
<< "wall? " << maze.IsWall(row, col) << std::endl
<< "clear? " << maze.IsClear(row, col) << std::endl
<< "path? " << maze.IsPath(row, col) << std::endl
<< "visited? " << maze.IsVisited(row, col) << std::endl
<< "exit? " << maze.IsExit(row, col) << std::endl << std::endl;
}
// Tests Mazes functions
void MazeTests() {
// Construct Maze with test file
Maze maze1(FILE1);
// Test public functions of Maze
PrintLocationInfo(maze1, 0, 0);
PrintLocationInfo(maze1, 0, 13);
PrintLocationInfo(maze1, 1, 13);
PrintLocationInfo(maze1, 1, 14);
}
void CreatureMazeTest(Maze* const maze, Creature* const creat) {
// Print the Creature to the console
std::cout << *creat << std::endl;
// Solve maze
std::cout << creat->Solve(*maze) << std::endl;
// Print maze to see visited spots and path
std::cout << *maze << std::endl;
}
// Tests maze in test.txt file from each open area
void Maze1Test() {
// Construct Maze with test file 1
Maze maze1(FILE1);
// Copy constructor
Maze maze2(maze1), maze3(maze1);
// Construct Creature at valid location in maze1 and test
Creature c1(0, 13);
CreatureMazeTest(&maze1, &c1);
// Construct Creature at valid location in maze2 and test
Creature c2(1, 13);
CreatureMazeTest(&maze2, &c2);
// Assignment operator overload
maze1 = maze2 = maze3;
// Construct Creature at valid location in maze1 and test
Creature c3(3, 13);
CreatureMazeTest(&maze1, &c3);
// Construct Creature at valid location in maze3 and test
Creature c4(3, 9);
CreatureMazeTest(&maze3, &c4);
// Get mazes blank again
maze1 = maze3 = maze2;
// Construct Creature at valid location in maze2 and test
Creature c5(8, 9);
CreatureMazeTest(&maze2, &c5);
// Construct Creature at valid location in maze3 and test
Creature c6(8, 6);
CreatureMazeTest(&maze3, &c6);
// Get mazes blank again
maze2 = maze3 = maze1;
// Construct Creature at valid location in maze2 and test
Creature c7(3, 2);
CreatureMazeTest(&maze2, &c7);
// Construct Creature at valid location in maze1 and test
Creature c8(5, 12);
CreatureMazeTest(&maze1, &c8);
// Construct Creature at valid location in maze3 and test
Creature c9(1, 3);
CreatureMazeTest(&maze3, &c9);
}
// Tests maze in test2.txt file from each open area
void Maze2Test() {
// Construct Maze with test2 file
Maze maze1(FILE2);
// Copy constructor
Maze maze2(maze1), maze3(maze1), maze4(maze1);
// Construct Creature at valid location in maze1 and test
Creature creat1(3, 1);
CreatureMazeTest(&maze1, &creat1);
// Construct Creature at valid location in maze2 and test
Creature creat2(7, 1);
CreatureMazeTest(&maze2, &creat2);
// Construct Creature at valid location in maze3 and test
Creature creat3(7, 5);
CreatureMazeTest(&maze3, &creat3);
// Assignment operator overload
maze1 = maze2 = maze3 = maze4;
// Construct Creature at valid location in maze1 and test
Creature creat4(6, 20);
CreatureMazeTest(&maze1, &creat4);
// Construct Creature at valid location in maze2 and test
Creature creat5(4, 14);
CreatureMazeTest(&maze2, &creat5);
// Construct Creature at valid location in maze3 and test
Creature creat6(2, 16);
CreatureMazeTest(&maze3, &creat6);
// Construct Creature at valid location in maze4 and test
Creature creat7(0, 9);
CreatureMazeTest(&maze4, &creat7);
}
// Runs all tests for Maze and Creature classes
void AllTests() {
MazeTests();
Maze1Test();
Maze2Test();
}
// Runs all tests functions
int main() {
AllTests();
}