-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokemon_battler.test.js
304 lines (269 loc) · 11 KB
/
pokemon_battler.test.js
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
303
304
const {
Pokemon,
Fire,
Grass,
Water,
Charmander,
Squirtle,
Bulbasaur,
Rattata,
Pokeball,
Trainer,
Battle,
} = require("./pokemon_battler");
describe("Pokemon", () => {
describe("Initialisation set up", () => {
test("Pokemon has a name property", () => {
const testPokemon = new Pokemon("pikachu");
expect(testPokemon.name).toBe("pikachu");
});
test("Pokemon has a type property", () => {
const testPokemon = new Pokemon("pikachu");
expect(testPokemon.type).toBe("normal");
});
test("Pokemon has a hitPoints property", () => {
const testPokemon = new Pokemon("pikachu", 35);
expect(testPokemon.hitPoints).toBe(35);
});
test("Pokemon has an attackDamage property", () => {
const testPokemon = new Pokemon("pikachu", 35, 55);
expect(testPokemon.attackDamage).toBe(55);
});
test("Pokemon has a move property", () => {
const testPokemon = new Pokemon("pikachu", 35, 55);
expect(testPokemon.move).toBe("tackle");
});
});
describe("Methods", () => {
test("isEffectiveAgainst returns the appropriate boolean", () => {
const flareon = new Fire("flareon", 65, 20);
const leafeon = new Grass("leafeon", 65, 17);
const vaporeon = new Water("vaporeon", 70, 19);
expect(flareon.isEffectiveAgainst(leafeon)).toBe(true);
expect(flareon.isEffectiveAgainst(vaporeon)).toBe(false);
});
test("isWeakTo returns the appropriate boolean", () => {
const flareon = new Fire("flareon", 65, 20);
const leafeon = new Grass("leafeon", 65, 17);
const vaporeon = new Water("vaporeon", 70, 19);
expect(flareon.isWeakTo(vaporeon)).toBe(true);
expect(leafeon.isWeakTo(vaporeon)).toBe(false);
});
test("takeDamage reduces hitPoints by the number passed in", () => {
const flareon = new Pokemon("flareon", 65, 20);
flareon.takeDamage(10);
expect(flareon.hitPoints).toBe(55);
});
test("useMove returns the Pokemon's attack damage", () => {
const flareon = new Pokemon("flareon", 65, 20);
expect(flareon.useMove()).toBe("flareon used tackle");
});
test("hasFainted returns a boolean of true when hitPoints <= 0, and false otherwise", () => {
const flareon = new Pokemon("flareon", 65, 20);
expect(flareon.hasFainted()).toBe(false);
flareon.takeDamage(65);
expect(flareon.hasFainted()).toBe(true);
});
});
describe("Pokemon inheritance", () => {
test("check that child class of Fire is a instanceof Pokemon", () => {
const flareon = new Fire("flareon", 65, 20);
expect(flareon instanceof Pokemon).toBe(true);
});
});
describe("Species Inheritance", () => {
test("check that child class of Charmander is an instanceof Fire", () => {
const charmander = new Charmander("firey", 65, 20);
expect(charmander instanceof Fire).toBe(true);
});
test("Charmander has a move called ember", () => {
const charmander = new Charmander("firey", 65, 20);
expect(charmander.move).toBe("ember");
});
test("check that child class of Squirtle is an instanceof Water", () => {
const squirtle = new Squirtle("watery", 65, 20);
expect(squirtle instanceof Water).toBe(true);
});
test("Squirtle has a move called water gun", () => {
const squirtle = new Squirtle("watery", 65, 20);
expect(squirtle.move).toBe("water gun");
});
test("check that child class of Bulbasaur is an instanceof Grass", () => {
const bulbasaur = new Bulbasaur("bulby", 65, 20);
expect(bulbasaur instanceof Grass).toBe(true);
});
test("Bulbasaur has a move called vine whip", () => {
const bulbasaur = new Bulbasaur("bulby", 65, 20);
expect(bulbasaur.move).toBe("vine whip");
});
test("check that child class of Rattata is an instanceof Pokemon", () => {
const rattata = new Rattata("ratty", 65, 20);
expect(rattata instanceof Pokemon).toBe(true);
});
test("Rattata has a move called tackle", () => {
const rattata = new Rattata("ratty", 65, 20);
expect(rattata.move).toBe("tackle");
});
});
describe("Pokeballs", () => {
test("a pokeball can store a pokemon", () => {
const testBall = new Pokeball();
expect(testBall.hasOwnProperty("store")).toBe(true);
});
test("a pokeball has a throw method", () => {
const testBall = new Pokeball();
const rattata = new Rattata("ratty", 65, 20);
testBall.throw(rattata);
expect(testBall.store).toEqual([rattata]);
});
test("a pokeball already holding a pokemon will not then catch a new pokemon", () => {
const testBall = new Pokeball();
const rattata = new Rattata("ratty", 65, 20);
const bulbasaur = new Bulbasaur("bulby", 65, 20);
testBall.throw(rattata);
expect(testBall.throw(bulbasaur)).toBe("Pokeball is full");
expect(testBall.store).toEqual([rattata]);
});
test("if using throw when the Pokeball is empty should recieve the right error message", () => {
const testBall = new Pokeball();
expect(testBall.throw()).toBe("Pokeball is empty");
expect(testBall.store).toEqual([]);
});
test("if using throw with now arguement when the ball is full should return the Pokemon", () => {
const testBall = new Pokeball();
const rattata = new Rattata("ratty", 65, 20);
testBall.throw(rattata);
expect(testBall.throw()).toEqual(rattata);
});
test(".isEmpty should return the correct boolean", () => {
const testBall = new Pokeball();
expect(testBall.isEmpty()).toBe(true);
const rattata = new Rattata("ratty", 65, 20);
testBall.throw(rattata);
expect(testBall.isEmpty()).toBe(false);
});
test(".contains should return the name of the Pokemon stored or whether it is empty", () => {
const testBall = new Pokeball();
expect(testBall.contains()).toBe("empty ...");
const rattata = new Rattata("ratty", 65, 20);
testBall.throw(rattata);
expect(testBall.contains()).toBe("ratty");
});
});
describe("Trainer", () => {
describe("Belt", () => {
test("trainer has a belt that can hold pokeballs", () => {
const trainer = new Trainer();
expect(trainer.hasOwnProperty("belt")).toBe(true);
expect(trainer.belt.length).toBe(6);
expect(trainer.belt[0] instanceof Pokeball).toBe(true);
});
});
describe(".catch", () => {
test("should use an empty pokeball's throw method to catch a given pokemon", () => {
const trainer = new Trainer();
const rattata = new Rattata("ratty", 65, 20);
trainer.catch(rattata);
expect(trainer.belt[0].store[0]).toBe(rattata);
const bulbasaur = new Bulbasaur("bulby", 65, 20);
trainer.catch(bulbasaur);
expect(trainer.belt[1].store[0]).toBe(bulbasaur);
});
test("Should return error message when all Pokeballs are full", () => {
const trainer = new Trainer();
const rattata = new Rattata("ratty", 65, 20);
trainer.catch(rattata);
trainer.catch(rattata);
trainer.catch(rattata);
trainer.catch(rattata);
trainer.catch(rattata);
trainer.catch(rattata);
expect(trainer.catch(rattata)).toBe("All your Pokeballs are full!");
});
test("If pokemon caught, assigns trainer correctly", () => {
const trainer = new Trainer("Ash");
const rattata = new Rattata("ratty", 65, 20);
trainer.catch(rattata);
expect(rattata.trainer).toBe(trainer);
});
});
describe(".getPokemon", () => {
test("returns the pokemon entered as an argument, if found", () => {
const trainer = new Trainer();
const rattata = new Rattata("ratty", 65, 20);
const bulbasaur = new Bulbasaur("bulby", 65, 20);
const squirtle = new Squirtle("watery", 65, 20);
trainer.catch(rattata);
trainer.catch(bulbasaur);
trainer.catch(squirtle);
expect(trainer.getPokemon("ratty")).toBe(rattata);
expect(trainer.getPokemon("watery")).toBe(squirtle);
});
});
});
describe("Battle!", () => {
test("Battle should take two trainers and two Pokemon as arguements", () => {
const jessica = new Trainer();
const joe = new Trainer();
const rattata = new Rattata("ratty", 65, 20);
const bulbasaur = new Bulbasaur("bulby", 65, 20);
jessica.catch(rattata);
joe.catch(bulbasaur);
const newBattle = new Battle(jessica, joe, "ratty", "bulby");
expect(newBattle.trainer1).toBe(jessica);
expect(newBattle.trainer2).toBe(joe);
expect(newBattle.trainer1pokemon).toBe(rattata);
expect(newBattle.trainer2pokemon).toBe(bulbasaur);
});
describe(".fight", () => {
test("pokemon given as an arguement can damage the other pokemon in the battle", () => {
const jessica = new Trainer();
const joe = new Trainer();
const rattata = new Rattata("ratty", 65, 20);
const bulbasaur = new Bulbasaur("bulby", 25, 10);
jessica.catch(rattata);
joe.catch(bulbasaur);
const newBattle = new Battle(jessica, joe, "ratty", "bulby");
newBattle.fight(newBattle.trainer1pokemon);
expect(bulbasaur.hitPoints).toBe(5);
newBattle.fight(newBattle.trainer2pokemon);
expect(rattata.hitPoints).toBe(55);
});
test("if defending pokemon is weak to the attacking pokemon it takes more damage", () => {
const jessica = new Trainer();
const joe = new Trainer();
const charmander = new Charmander("firey", 65, 20);
const bulbasaur = new Bulbasaur("bulby", 45, 10);
jessica.catch(charmander);
joe.catch(bulbasaur);
const newBattle = new Battle(jessica, joe, "firey", "bulby");
newBattle.fight(newBattle.trainer1pokemon);
expect(bulbasaur.hitPoints).toBe(20);
});
test("if defending pokemon is strong to the attacking pokemon it takes less damage", () => {
const jessica = new Trainer("jessica");
const joe = new Trainer("joe");
const charmander = new Charmander("firey", 65, 20);
const bulbasaur = new Bulbasaur("bulby", 45, 20);
jessica.catch(charmander);
joe.catch(bulbasaur);
const newBattle = new Battle(jessica, joe, "firey", "bulby");
newBattle.fight(newBattle.trainer2pokemon);
expect(charmander.hitPoints).toBe(50);
});
test("when defending pokemon faints, returns an appropriate message", () => {
const jessica = new Trainer("jessica");
const joe = new Trainer("joe");
const charmander = new Charmander("firey", 65, 100);
const bulbasaur = new Bulbasaur("bulby", 45, 20);
jessica.catch(charmander);
joe.catch(bulbasaur);
const newBattle = new Battle(jessica, joe, "firey", "bulby");
expect(newBattle.fight(newBattle.trainer1pokemon)).toBe(
"bulby fainted!"
);
expect(bulbasaur.hasFainted()).toBe(true);
});
});
});
});