-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBulbasaurTest.java
More file actions
280 lines (262 loc) · 11 KB
/
BulbasaurTest.java
File metadata and controls
280 lines (262 loc) · 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
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
import org.junit.Assert;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class BulbasaurTest {
static final int BASE_ATTACK = 126;
static final int BASE_DEFENSE = 126;
static final int BASE_STAMINA = 90;
static final String[] BULBA_FAST_ATTACKS = {"Razor Leaf", "Vine Whip","Acid", "Poison Jab", "Poison Sting"};
static final String[] BULBA_SPECIAL_ATTACKS = {"Leaf Blade", "Petal Blizzard", "Power Whip","Seed Bomb",
"Solar Beam","Cross Poison", "Gunk Shot", "Poison Fang","Sludge", "Sludge Bomb",
"Sludge Wave"};
public static final double[] cpMultiplier = {0.094, 0.16639787, 0.21573247, 0.25572005, 0.29024988,
0.3210876 , 0.34921268, 0.37523559, 0.39956728, 0.42250001,
0.44310755, 0.46279839, 0.48168495, 0.49985844, 0.51739395,
0.53435433, 0.55079269, 0.56675452, 0.58227891, 0.59740001,
0.61215729, 0.62656713, 0.64065295, 0.65443563, 0.667934 ,
0.68116492, 0.69414365, 0.70688421, 0.71939909, 0.7317 ,
0.73776948, 0.74378943, 0.74976104, 0.75568551, 0.76156384,
0.76739717, 0.7731865 , 0.77893275, 0.78463697, 0.79030001};
/** Fixture initialization (common initialization
* for all tests). **/
@Before public void setUp() {
}
/* Constructor no nickName test - nickName same as name if not specified **/
@Test public void noNickNameTest(){
Pokemon p = new Bulbasaur();
Assert.assertEquals("Name and nickName should be the same.", p.getName(), "Bulbasaur");
}
/* Is fast attack in allowed attack list? */
@Test public void fastAttackAssignmentTest(){
Pokemon p = new Bulbasaur();
String atk = p.getFastAttack();
boolean isInList = false;
int i = 0;
while((!isInList) && (i < BULBA_FAST_ATTACKS.length)){
isInList = atk.equals(BULBA_FAST_ATTACKS[i]);
i++;
}
Assert.assertTrue("Bulbasaur fast attack " + atk + " should be grass or poison, is not", isInList);
}
/* Is special attack in allowed attack list? */
@Test public void specialAttackAssignmentTest(){
Pokemon p = new Bulbasaur();
String atk = p.getSpecialAttack();
boolean isInList = false;
int i = 0;
while((!isInList) && (i < BULBA_SPECIAL_ATTACKS.length)){
isInList = atk.equals(BULBA_SPECIAL_ATTACKS[i]);
i++;
}
Assert.assertTrue("Bulbasaur special attack " + atk + " should be grass or poison, is not", isInList);
}
/* testing toString method
* checks that toString is properly formatted.
*/
@Test
public void toStringTest(){
Pokemon p = new Bulbasaur();
int hP = p.getHP();
int cP = p.getCP();
Assert.assertEquals("toString format is incorrect.",
"Species: Bulbasaur\nNumber: 001\nHeight: 0.71\nWeight: 6.9\nType: Grass | Poison\nHP: "+hP+"\nCP: "+cP,
p.toString());
}
@Test public void toStringTest2(){
Pokemon p = new Bulbasaur("Bob");
int hP = p.getHP();
int cP = p.getCP();
Assert.assertEquals("toString format is incorrect.",
"Species: Bulbasaur\nName: Bob\nNumber: 001\nHeight: 0.71\nWeight: 6.9\nType: Grass | Poison\nHP: "+hP+"\nCP: "+cP,
p.toString());
}
/* Check that string output from fast attack on Bulbasaur is correct */
@Test public void performFastAttackTest1(){
String[] gFastAtks = {"Razor Leaf", "Vine Whip"};
Pokemon p = new Bulbasaur();
Pokemon p2 = new Bulbasaur();
String pFA = p.getFastAttack();
int i = 0;
boolean pAtkGrass = false;
while((!pAtkGrass) && (i < gFastAtks.length)){
pAtkGrass = pFA.equals(gFastAtks[i]);
i++;
}
if(pAtkGrass){
Assert.assertEquals("String output from fast attack on Bulbasaur is not as expected",
"Bulbasaur performed " + pFA + " on Bulbasaur\n It was not very effective.",
p.performFastAttack(p2));
}else{
Assert.assertEquals("String output from fast attack on Bulbasaur is not as expected",
"Bulbasaur performed " + pFA + " on Bulbasaur\n It was super effective!", p.performFastAttack(p2));
}
}
@Test public void performFastAttackTest2(){
String[] gFastAtks = {"Razor Leaf", "Vine Whip"};
Pokemon p = new Bulbasaur();
Pokemon p2 = new Squirtle();
String pFA = p.getFastAttack();
int i = 0;
boolean pAtkGrass = false;
while((!pAtkGrass) && (i < gFastAtks.length)){
pAtkGrass = pFA.equals(gFastAtks[i]);
i++;
}
if(pAtkGrass){
Assert.assertEquals("String output from fast attack on Water Type is not as expected",
"Bulbasaur performed " + pFA + " on Squirtle\n It was super effective!",
p.performFastAttack(p2));
}else{
Assert.assertEquals("String output from fast attack on Water Type is not as expected",
"Bulbasaur performed " + pFA + " on Squirtle", p.performFastAttack(p2));
}
}
/*performFastAttack on Charmander/fire type */
@Test public void performFastAttackTest3(){
String[] gFastAtks = {"Razor Leaf", "Vine Whip"};
Pokemon p = new Bulbasaur();
Pokemon p2 = new Charmander();
String pFA = p.getFastAttack();
int i = 0;
boolean pAtkGrass = false;
while((!pAtkGrass) && (i < gFastAtks.length)){
pAtkGrass = pFA.equals(gFastAtks[i]);
i++;
}
if(pAtkGrass){
Assert.assertEquals("String output from fast attack on Fire Type is not as expected",
"Bulbasaur performed " + pFA + " on Charmander\n It was not very effective.",
p.performFastAttack(p2));
}else{
Assert.assertEquals("String output from fast attack on Fire Type is not as expected",
"Bulbasaur performed " + pFA + " on Charmander", p.performFastAttack(p2));
}
}
/* Check that string output from special attack on Bulbasaur is correct */
@Test public void performSpecialAttackTest1(){
String[] gSpecialAtks = {"Leaf Blade", "Petal Blizzard", "Power Whip","Seed Bomb", "Solar Beam"};
Pokemon p = new Bulbasaur();
Pokemon p2 = new Bulbasaur();
String pSA = p.getSpecialAttack();
int i = 0;
boolean pAtkGrass = false;
while((!pAtkGrass) && (i < gSpecialAtks.length)){
pAtkGrass = pSA.equals(gSpecialAtks[i]);
i++;
}
if(pAtkGrass){
Assert.assertEquals("String output from special attack on Bulbasaur is not as expected",
"Bulbasaur performed " + pSA + " on Bulbasaur\n It was not very effective.",
p.performSpecialAttack(p2));
}else{
Assert.assertEquals("String output from special attack on Bulbasaur is not as expected",
"Bulbasaur performed " + pSA + " on Bulbasaur\n It was super effective!", p.performSpecialAttack(p2));
}
}
/* perform special attack on Squirtle/water type */
@Test public void performSpecialAttackTest2(){
String[] gSpecialAtks = {"Leaf Blade", "Petal Blizzard", "Power Whip","Seed Bomb", "Solar Beam"};
Pokemon p = new Bulbasaur();
Pokemon p2 = new Squirtle();
String pSA = p.getSpecialAttack();
int i = 0;
boolean pAtkGrass = false;
while((!pAtkGrass) && (i < gSpecialAtks.length)){
pAtkGrass = pSA.equals(gSpecialAtks[i]);
i++;
}
if(pAtkGrass){
Assert.assertEquals("String output from special attack on Water Type is not as expected",
"Bulbasaur performed " + pSA + " on Squirtle\n It was super effective!",
p.performSpecialAttack(p2));
}else{
Assert.assertEquals("String output from special attack on Water Type is not as expected",
"Bulbasaur performed " + pSA + " on Squirtle", p.performSpecialAttack(p2));
}
}
/* perform special attack on Charmander/fire type */
@Test public void performSpecialAttackTest3(){
String[] gSpecialAtks = {"Leaf Blade", "Petal Blizzard", "Power Whip","Seed Bomb", "Solar Beam"};
Pokemon p = new Bulbasaur();
Pokemon p2 = new Charmander();
String pSA = p.getSpecialAttack();
int i = 0;
boolean pAtkGrass = false;
while((!pAtkGrass) && (i < gSpecialAtks.length)){
pAtkGrass = pSA.equals(gSpecialAtks[i]);
i++;
}
if(pAtkGrass){
Assert.assertEquals("String output from special attack on Fire Type is not as expected",
"Bulbasaur performed " + pSA + " on Charmander\n It was not very effective.",
p.performSpecialAttack(p2));
}else{
Assert.assertEquals("String output from special attack on Fire Type is not as expected",
"Bulbasaur performed " + pSA + " on Charmander", p.performSpecialAttack(p2));
}
}
/*HP constructor test
* Checks that HP in range
* HP is base stamina (90) + a random
* Run it 5 times to check due to randomness
*/
@Test public void hpRangeTest1(){
double cpMult = cpMultiplier[0];
int minHP = (int)(BASE_STAMINA * cpMult);
Pokemon p = new Bulbasaur();
Assert.assertTrue("HP not >= " + minHP,(minHP <= p.getHP()));
}
@Test public void hpRangeTest2(){
double cpMult = cpMultiplier[0];
int minHP = (int)(BASE_STAMINA * cpMult);
Pokemon p = new Bulbasaur();
Assert.assertTrue("HP not >= " + minHP,(minHP <= p.getHP()));
}
@Test public void hpRangeTest3(){
double cpMult = cpMultiplier[0];
int minHP = (int)(BASE_STAMINA * cpMult);
Pokemon p = new Bulbasaur();
Assert.assertTrue("HP not >= " + minHP,(minHP <= p.getHP()));
}
@Test public void hpRangeTest4(){
double cpMult = cpMultiplier[0];
int minHP = (int)(BASE_STAMINA * cpMult);
Pokemon p = new Bulbasaur();
Assert.assertTrue("HP not >= " + minHP,(minHP <= p.getHP()));
}
@Test public void hpRangeTest5(){
double cpMult = cpMultiplier[0];
int minHP = (int)(BASE_STAMINA * cpMult);
Pokemon p = new Bulbasaur();
Assert.assertTrue("HP not >= " + minHP,(minHP <= p.getHP()));
}
/*CP constructor test
* Checks that CP in range*
* Run it 5 times to check due to randomness
*/
@Test public void cpRangeTest1(){
int minCP = 10;
Pokemon p = new Bulbasaur();
Assert.assertTrue("CP " + p.getCP()+" not <= " + minCP,(minCP <= p.getCP()));
}
@Test public void cpRangeTest2(){
int minCP = 10;
Pokemon p = new Bulbasaur();
Assert.assertTrue("CP " + p.getCP()+" not <= " + minCP,(minCP <= p.getCP())); }
@Test public void cpRangeTest3(){
int minCP = 10;
Pokemon p = new Bulbasaur();
Assert.assertTrue("CP " + p.getCP()+" not <= " + minCP,(minCP <= p.getCP()));
}
@Test public void cpRangeTest4(){
int minCP = 10;
Pokemon p = new Bulbasaur();
Assert.assertTrue("CP " + p.getCP()+" not <= " + minCP,(minCP <= p.getCP()));
}
@Test public void cpRangeTest5(){
int minCP = 10;
Pokemon p = new Bulbasaur();
Assert.assertTrue("CP " + p.getCP()+" not <= " + minCP,(minCP <= p.getCP()));
}
}