-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.cpp
More file actions
302 lines (236 loc) · 7.37 KB
/
Copy pathtesting.cpp
File metadata and controls
302 lines (236 loc) · 7.37 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#include "Entity.h"
#include "Obstacle.h"
#include <iostream>
#include <string>
#include "Maze.h"
#include "Person.h"
#include <curses.h>
#include "Banana.h"
#include "Hole.h"
#include "Wall.h"
#include "Space.h"
#include "Finish.h"
using namespace std;
int main (void) {
//Entity class testing
cout << endl;
cout<< "testing Entity class" << endl;
Entity *entity;
entity = new Entity();
char inp = '#';
//compares get sprite to value passed to set sprite
entity->setSprite(inp);
if (entity->getSprite() == inp) {
cout << "success: setSprite \n";
} else {
cout << "fail: setSprite \n";
}
// Wall class testing
cout << endl;
cout<< "testing Wall class" << endl;
Wall *wall;
wall = new Wall();
//checks that the isWall function can correctly identify a wall
if (wall->isWall()) {
cout << "success: wall is wall\n";
} else {
cout << "fail: wall not wall\n";
}
//maze class testing
Person *person;
Maze *maze;
Space *space;
int MAPHEIGHT=10, MAPWIDTH=10, STARTYPOS=2, STARTXPOS=2;
person = new Person();
maze = new Maze(MAPHEIGHT, MAPWIDTH, STARTYPOS, STARTXPOS);
space = new Space();
cout << endl;
cout<< "testing maze class" << endl;
//Checks that the getMapHeight and getMapWidth functions return the values
//set to the maze constructor
if (maze->getMapHeight() == MAPHEIGHT && maze->getMapWidth() == MAPWIDTH) {
cout << "success: map dimensions match\n";
} else {
cout << "fail: map dimensions don't match\n";
}
//creates a map
Obstacle*** Map = new Obstacle**[MAPHEIGHT];
for (int i = 0; i < MAPHEIGHT; ++i) {
Map[i] = new Obstacle*[MAPWIDTH];
for (int j = 0; j < MAPWIDTH; ++j) {
if (i==0 || i== MAPHEIGHT-1 || j == 0 || j == MAPWIDTH-1) {
Map[i][j]= wall;
} else {
Map[i][j]=space;
}
}
}
//checks that the getMap function returns the expected map
maze->setMap(Map);
bool mapCheck = 0;
for (int i = 0; i < MAPHEIGHT; ++i) {
for (int j = 0; j < MAPWIDTH; ++j)
if (maze->getMap()[i][j] == Map[i][j]) {
mapCheck = 1;
} else {
mapCheck = 0;
break;
}
}
if (mapCheck)
{
cout << "sucess: maps match\n";
} else {
cout << "maps don't match\n";
}
for (int i = 0; i < MAPHEIGHT; ++i)
{
delete[] Map[i];
}
delete[] Map;
//checks if the drawMap function is successful
if (maze->drawMap(person)) {
cout << "success: map is drawn successfully\n";
} else {
cout << "fail: map was not drawn\n";
}
//checks the getCurrentObstacle returns the correct obstacle that the person is on
person->setPos(2,2, maze);
if (maze->getCurrentObstacle(person)==space)
{
cout << "success: getCurrentObstacle\n";
} else {
cout << "fail: getCurrentObstacle\n";
}
//checks the getNextObstacle returns the correct obstacle surrounding the person in all directions
if (maze->getNextObstacle(person,KEY_RIGHT)==space && maze->getNextObstacle(person,KEY_LEFT)==space && maze->getNextObstacle(person,KEY_UP)==space && maze->getNextObstacle(person,KEY_DOWN)==space)
{
cout << "success: getNextObstacle\n";
} else {
cout << "fail: getNextObstacle\n";
}
//check the getStartY and getStartX functions
if (maze->getStartY() == STARTYPOS && maze->getStartX() == STARTXPOS)
{
cout << "success: start position is correct\n";
} else {
cout << "fail: start position does not match\n";
}
//test creating an invalid map with negative dimensions
Maze* negMaze = new Maze(-5,-4,2,2);
if (negMaze->getMapWidth() == 0 && negMaze->getMapHeight()==0)
{
cout << "success: map with negative dimensions is not created\n";
} else {
cout << "fail: map with negative dimensions does not default to 0s\n";
}
//test creating an invalid map with zero dimensions
Maze* zeroMaze = new Maze(0,0,2,2);
if (zeroMaze->getMapWidth() == 0 && zeroMaze->getMapHeight()==0)
{
cout << "success: map with zero dimensions is not created\n";
} else {
cout << "fail: map with zero dimensions does not default to 0s\n";
}
delete zeroMaze;
delete negMaze;
//Person class testing
cout << endl;
cout<< "testing person class" << endl;
int xPos=3, yPos=3;
//compares the getxPos and getyPos values to the inputted setPos values
person->setPos(xPos, yPos, maze);
if (person->getxPos()== xPos && person->getyPos()== yPos) {
cout << "success: setPos\n";
} else {
cout << "fail: setPos\n";
}
//checks that the string returned from getName is the string that was passed to
//setName
string name = "myName";
person->setName(name);
if (person->getName() == name)
{
cout << "success: setName\n";
} else {
cout << "fail: setName\n";
}
//Checks if the person object can move in all four directions over a space
person->move(maze, KEY_RIGHT);
if (person->getxPos() == xPos++ && person->getyPos() == yPos)
{
cout << "success: person move (right)\n";
}
person->move(maze, KEY_LEFT);
if (person->getxPos() == xPos-- && person->getyPos() == yPos)
{
cout << "success: person move (left)\n";
}
person->move(maze, KEY_UP);
if (person->getxPos() == xPos && person->getyPos() == yPos--)
{
cout << "success: person move (up)\n";
}
person->move(maze, KEY_DOWN);
if (person->getxPos() == xPos && person->getyPos() == yPos++)
{
cout << "success: person move (down)\n";
}
//checks that the person object does not move into a wall
person->setPos(1,1, maze);
person->move(maze, KEY_UP);
if (person->getxPos() == 1 && person->getyPos() == 1)
{
cout << "success: person can't move into wall\n";
} else {
cout << "fail: person moved when wall should block them";
}
//checks that the drawPerson function is sucessful
if (person->drawPerson()) {
cout << "success: drawPerson";
} else {
cout << "fail: drawPerson";
}
//Obstacle class testing
cout << endl;
cout<< "\ntesting Obstacle class" << endl;
Obstacle *obstacle;
obstacle = new Obstacle(inp, "message");
//checks that an obstacle can identify when a person is moved on to it from
//all four directions
if (obstacle->touched(maze, person, KEY_LEFT)==0 && obstacle->touched(maze, person, KEY_RIGHT)==0 && obstacle->touched(maze, person, KEY_UP)==0 && obstacle->touched(maze, person, KEY_DOWN) ==0) {
cout << "obstacle touched: success\n";
} else {
cout << "obstacle touched: failed\n";
}
// Banana class testing
cout << endl;
cout<< "testing Banana class" << endl;
Banana *banana;
banana = new Banana();
Map[1][2] = banana;
maze->setMap(Map);
person->move(maze, KEY_RIGHT);
//checks that a banana moves a person to the expected position
if (person->getxPos() == 8 && person->getyPos() == 1) {
cout << "success: banana moved player to expected position";
} else {
cout << "fail: banana did not move player to expected position";
}
//Hole class testing
cout << endl;
cout<< "\ntesting Hole class" << endl;
Hole *hole;
hole = new Hole();
Map[2][8] = hole;
maze->setMap(Map);
person->move(maze, KEY_DOWN);
//checks that a hole moves a person to the expected position
if (person->getxPos() == 2 && person->getyPos() == 2)
{
cout << "success: Hole moved player to 2,2\n";
} else {
cout << "fail: Hole did not move player to 2,2\n";
}
return 0;
}