-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteststage3.cpp
More file actions
228 lines (211 loc) · 7.11 KB
/
teststage3.cpp
File metadata and controls
228 lines (211 loc) · 7.11 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
#include "teststage3.h"
TestStage3::TestStage3(std::unique_ptr<GameStateFactory>& factory):
state(factory->createGameState()),
num_cases_passed(0) {
}
void TestStage3::run() {
testLargePowerup();
testTinyPowerup();
testNormalPowerup();
testGiantPowerup();
testLoseLife();
testGainLife();
testSpeedPowerup();
testReset();
testGameover();
testCheckpointNextLevel();
testCheckpointWin();
qDebug() << "Number of test cases passed:" << num_cases_passed << "/11";
}
/*
* This check if mediator correctly change Stickman size
* Expected the gravity to change as Large powerup makes you jump higher
*/
void TestStage3::testLargePowerup() {
qDebug() << "1) testLargePowerup";
dynamic_cast<Mediator*>(state)->largePowerup();
qDebug() << "Expected: " << -3920 << "Actual: " << state->getPlayer()->getGravity();
if (int(state->getPlayer()->getGravity()) == -int(9.8 * 400)) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly change Stickman size
* Expected the size to change to tiny
*/
void TestStage3::testTinyPowerup() {
qDebug() << "2) testTinyPowerup";
dynamic_cast<Mediator*>(state)->tinyPowerup();
std::string actual = Config::config()->getStickman()->getSize();
qDebug() << "Expected: " << "tiny" << "Actual: " << actual.c_str();
if (actual == "tiny") {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly change Stickman size
* Expected the size to change to normal
*/
void TestStage3::testNormalPowerup() {
qDebug() << "3) testNormalPowerup";
dynamic_cast<Mediator*>(state)->normalPowerup();
std::string actual = Config::config()->getStickman()->getSize();
qDebug() << "Expected: " << "normal" << "Actual: " << actual.c_str();
if (actual == "normal") {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly change Stickman size
* Expected the size to change to giant and check if colliding with obstacle
* makes you inmmune (lose no life)
*/
void TestStage3::testGiantPowerup() {
qDebug() << "4) testGiantPowerup";
dynamic_cast<Mediator*>(state)->giantPowerup();
std::string actual = Config::config()->getStickman()->getSize();
qDebug() << "Expected: " << "giant" << "Actual: " << actual.c_str();
if (actual == "giant") {
int live = state->getPlayer()->getLives();
state->setPlayerColliding(true);
dynamic_cast<Mediator*>(state)->checkCollisions();
qDebug() << "Expected: " << live << "Actual: " << state->getPlayer()->getLives();
if (live == state->getPlayer()->getLives()) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly change Stickman lives
* Expected life to decrease by 1
*/
void TestStage3::testLoseLife() {
qDebug() << "5) testLoseLife";
dynamic_cast<Mediator*>(state)->normalPowerup();
state->setPlayerColliding(true);
dynamic_cast<Mediator*>(state)->checkCollisions();
qDebug() << "Expected: 2 Actual: " << state->getPlayer()->getLives();
if (state->getPlayer()->getLives() == 2) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly change Stickman lives
* Expected life to increase by 1
*/
void TestStage3::testGainLife() {
qDebug() << "6) testGainLife";
dynamic_cast<Mediator*>(state)->heart();
qDebug() << "Expected: 3 Actual: " << state->getPlayer()->getLives();
if (state->getPlayer()->getLives() == 3) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly change Stickman speed
* Expected the speed of stickman to increase
*/
void TestStage3::testSpeedPowerup() {
qDebug() << "7) testSpeedPowerup";
int speed = Config::config()->getInitialVelocity();
dynamic_cast<Mediator*>(state)->speedup();
qDebug() << "Expected: " << speed * 2 << " Actual: " << Config::config()->getVelocity();
if (Config::config()->getVelocity() == speed * 2) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly reset when Stickman hits obstacle
* Expected collision to be false as when it reset the Stickman no longer colliding
*/
void TestStage3::testReset() {
qDebug() << "8) testReset";
dynamic_cast<Mediator*>(state)->normalPowerup();
state->setPlayerColliding(true);
dynamic_cast<Mediator*>(state)->checkCollisions();
qDebug() << "Expected: false Actual: " << state->getPlayerColliding();
if (!state->getPlayerColliding()) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly go to Gameover
* Simulate player colliding to obstacle with 1 life left
* Expected life to decrease to 0 and then game finished is true but not won
*/
void TestStage3::testGameover() {
qDebug() << "9) testGameover";
dynamic_cast<Mediator*>(state)->normalPowerup();
state->getPlayer()->setLives(1);
state->setPlayerColliding(true);
dynamic_cast<Mediator*>(state)->checkCollisions();
qDebug() << "Expected: finished == true and lives == 0 Actual: " << dynamic_cast<Mediator*>(state)->isFinished()
<< " " << state->getPlayer()->getLives();
if (state->getPlayer()->getLives() == 0 && dynamic_cast<Mediator*>(state)->isFinished() &&
!dynamic_cast<Mediator*>(state)->didWon()) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly go to next level
* Expected current level for stickman to + 1
*/
void TestStage3::testCheckpointNextLevel() {
qDebug() << "10) testCheckpointNextLevel";
int level = state->getPlayer()->getCurrentLevel();
dynamic_cast<Mediator*>(state)->checkpoint();
qDebug() << "Expected: " << level + 1 << "Actual: " << state->getPlayer()->getCurrentLevel();
if (state->getPlayer()->getCurrentLevel() == level + 1) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}
/*
* This check if mediator correctly go to Winning state
* Simulate player going to checkpoint at final level
* Expected game finished is true and also won
*/
void TestStage3::testCheckpointWin() {
qDebug() << "11) testCheckpointWin";
state->getPlayer()->setCurrentLevel(2);
dynamic_cast<Mediator*>(state)->setNumLevels(2);
dynamic_cast<Mediator*>(state)->checkpoint();
qDebug() << "Expected: " << "True" << "Actual: " << dynamic_cast<Mediator*>(state)->didWon();
if (dynamic_cast<Mediator*>(state)->didWon() && dynamic_cast<Mediator*>(state)->isFinished()) {
qDebug() << "Pass!";
num_cases_passed++;
} else {
qDebug() << "Fail!";
}
}