-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiny_attack_test.cpp
More file actions
124 lines (100 loc) · 2.86 KB
/
tiny_attack_test.cpp
File metadata and controls
124 lines (100 loc) · 2.86 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
#include <iostream>
#include <string>
#include "TinyAttack.h"
bool testType(TinyAttack *ta, string expected) {
if(ta->getType() == expected) {
return true;
}
else {
cout << "Failed typecheck. Expected " << expected << ", received " << ta->getType() << endl;
return false;
}
}
bool testPower(TinyAttack *ta, int expected) {
if(ta->getPower() == expected) {
return true;
}
else {
cout << "Failed power check. Expected " << expected << ", received " << ta->getPower() << endl;
return false;
}
}
bool testPP(TinyAttack *ta, int expected) {
if(ta->getPP() == expected) {
return true;
}
else {
cout << "Failed pp (or use) check. Expected " << expected << ", received " << ta->getPP() << endl;
return false;
}
}
bool testSpeed(TinyAttack *ta, int expected) {
if(ta->getSpeed() == expected) {
return true;
}
else {
cout << "Failed speed check. Expected " << expected << ", received " << ta->getSpeed() << endl;
return false;
}
}
bool testUse(TinyAttack *ta) {
int prePP = ta->getPP();
if(prePP == 0) {
return false;
}
ta->use();
return testPP(ta, prePP - 1);
}
void runTests(string type, int power,int pp, int speed) {
double testsRun = 0;
double testsPassed = 0;
int round;
TinyAttack *ta = new TinyAttack(type, power, pp, speed);
TinyAttack *taCopy = new TinyAttack(type, power, pp, speed);
TinyAttack *wrongType = new TinyAttack("test", power, pp, speed);
TinyAttack *wrongPower = new TinyAttack(type, power + 1, pp, speed);
TinyAttack *wrongSpeed = new TinyAttack(type, power, pp, speed * 2);
cout << "---------------------------------------------------------" << endl;
cout << "Running tests on: " << endl;
ta->print();
cout << "*********************************************************" << endl;
testsRun++;
if(testType(ta, type)) {
testsPassed++;
}
testsRun++;
if(testPower(ta, power)) {
testsPassed++;
}
testsRun++;
if(testPP(ta, pp)) {
testsPassed++;
}
testsRun++;
if(testSpeed(ta, speed)) {
testsPassed++;
}
testsRun++;
if(testUse(ta)) {
testsPassed++;
}
testsRun++;
if(ta->equals(taCopy) && !ta->equals(wrongType) && !ta->equals(wrongPower) && !ta->equals(wrongSpeed)) {
testsPassed++;
}
else cout << "failed equality test" << endl;
round = testsPassed/testsRun * 100;
cout << "Passed " << testsPassed << " out of " << testsRun << "! Pass Rate: " << round << "%" << endl;
cout << "********************************************************" << endl;
delete ta;
delete taCopy;
delete wrongType;
delete wrongPower;
delete wrongSpeed;
}
int main(int args, char** argv) {
cout <<"Creating tests..." << endl;
runTests("damage", -5, 25, 5);
runTests("heal", 10, 5, 20);
return 1;
}