-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathStudentTest1.cpp
More file actions
668 lines (531 loc) · 22.9 KB
/
StudentTest1.cpp
File metadata and controls
668 lines (531 loc) · 22.9 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
#include "doctest.h"
#include "sources/Character.hpp"
#include "sources/OldNinja.hpp"
#include "sources/YoungNinja.hpp"
#include "sources/TrainedNinja.hpp"
#include "sources/Cowboy.hpp"
#include "sources/Team.hpp"
#include "sources/Team2.hpp"
#include <random>
#include <chrono>
#include <iostream>
using namespace ariel;
using namespace std;
//<--------------------Helper Functions-------------------->
//https://www.geeksforgeeks.org/generate-a-random-float-number-in-cpp/
double random_float(double min = -100, double max = 100) {
std::default_random_engine generator(static_cast<unsigned long>(std::chrono::system_clock::now().time_since_epoch().count()));
std::uniform_real_distribution<double> distribution(min, max);
return distribution(generator);
}
auto create_yninja = [](double x = random_float(), double y = random_float()) {
return new YoungNinja{"Bob", Point{x, y}};
};
auto create_tninja = [](double x = random_float(), double y = random_float()) {
return new TrainedNinja{"Bob", Point{x, y}};
};
auto create_oninja = [](double x = random_float(), double y = random_float()) {
return new OldNinja{"Bob", Point{x, y}};
};
auto create_cowboy = [](double x = random_float(), double y = random_float()) {
return new Cowboy{"Bob", Point{x, y}};
};
auto random_char(double x = random_float(), double y = random_float()) -> Character * {
int flag = static_cast<int>(random_float()) % 4;
if (flag == 0) return create_cowboy(x, y);
if (flag == 1) return create_yninja(x, y);
if (flag == 2) return create_tninja(x, y);
return create_oninja(x, y);
}
auto simulate_battle = [](Team &team, Team &team2) {
int i = 0;
while (team.stillAlive() && team2.stillAlive()) {
if (i % 2 == 0) {
team.attack(&team2);
} else {
team2.attack(&team);
}
i++;
}
};
//<-------------------------------------------------->
const int MAX_TEAM = 10;
TEST_SUITE("Point class tests") {
Point p1{1, 1};
Point p2{2, 3};
Point n1{-1, 1};
Point n2{1, -9};
Point n3{-1, -1};
TEST_CASE("Distance method") {
CHECK_EQ(p1.distance(p2), p2.distance(p1));
CHECK_EQ(n1.distance(n2), n2.distance(n1));
CHECK_EQ(n3.distance(p1), p1.distance(n3));
CHECK_EQ(n2.distance(p1), 10);
CHECK_EQ(p2.distance(n3), 5);
CHECK_EQ(p1.distance(p1), 0);
}
TEST_CASE("moveTowards method") {
double distance = p1.distance(p2);
double half_p = distance / 2;
double third_p = distance / 3;
Point p3{Point::moveTowards(p1, p2, half_p)};
CHECK_EQ(p3.distance(p2), doctest::Approx(half_p).epsilon(0.001));
Point p4{Point::moveTowards(p1, p2, third_p)};
CHECK_EQ(p4.distance(p2), doctest::Approx(third_p * 2).epsilon(0.001));
// There is no such a thing as negative distance
CHECK_THROWS_AS(Point::moveTowards(p1, p2, -1),std::invalid_argument);
}
}
TEST_SUITE("Classes initialization tests and Team modification( add(),stillAlive() )") {
TEST_CASE("Cowboy initialization") {
Cowboy cowboy{"Bob", Point{2, 3}};
CHECK(cowboy.hasboolets());
CHECK_EQ(cowboy.getName(), "Bob");
CHECK_EQ(cowboy.getLocation().distance(Point{2, 3}), 0);
CHECK_NE(cowboy.getLocation().distance(Point{3, 2}), 0);
CHECK(cowboy.isAlive());
}
TEST_CASE("YoungNinja initialization") {
YoungNinja ninja{"Bob", Point{2, 3}};
CHECK_EQ(ninja.getName(), "Bob");
CHECK_EQ(ninja.getLocation().distance(Point{2, 3}), 0);
CHECK_NE(ninja.getLocation().distance(Point{3, 2}), 0);
CHECK(ninja.isAlive());
}
TEST_CASE("OldNinja initialization") {
OldNinja old_ninja{"Bob", Point(2, 3)};
CHECK_EQ(old_ninja.getName(), "Bob");
CHECK_EQ(old_ninja.getLocation().distance(Point{2, 3}), 0);
CHECK_NE(old_ninja.getLocation().distance(Point{3, 2}), 0);
CHECK(old_ninja.isAlive());
}
TEST_CASE("TrainedNinja initialization") {
TrainedNinja trained_ninja{"Bob", Point{2, 3}};
CHECK_EQ(trained_ninja.getName(), "Bob");
CHECK_EQ(trained_ninja.getLocation().distance(Point{2, 3}), 0);
CHECK_NE(trained_ninja.getLocation().distance(Point{3, 2}), 0);
CHECK(trained_ninja.isAlive());
}
TEST_CASE("Team initialization") {
auto cowboy = create_cowboy(2, 3);
auto ninja = create_yninja(2, 3);
Team team{cowboy};
CHECK_EQ(team.stillAlive(), 1);
Team2 team2{ninja};
CHECK_EQ(team2.stillAlive(), 1);
}
TEST_CASE("Team class add() and stillAlive() methods") {
auto captain1 = create_oninja();
auto captain2 = create_yninja();
Team team1{captain1};
Team2 team2{captain2};
// Every addition should rise the value returned by stillAlive()
for (int i = 0; i < MAX_TEAM - 1; i++) {
auto cur1 = create_tninja();
auto cur2 = create_cowboy();
team1.add(cur1);
team2.add(cur2);
CHECK_EQ(team1.stillAlive(), i + 2);
CHECK_EQ(team2.stillAlive(), i + 2);
}
// A team can have at most 10 teammates
auto over = create_cowboy();
CHECK_THROWS_AS(team1.add(over),std::runtime_error);
CHECK_THROWS_AS(team2.add(over),std::runtime_error);
delete over;
}
TEST_CASE("Appointing the same captain to different teams") {
auto captain = create_cowboy();
auto captain2 = create_yninja();
Team team1{captain};
CHECK_THROWS_AS(Team{captain},std::runtime_error);
CHECK_THROWS_AS(Team2{captain},std::runtime_error);
Team team2{captain2};
CHECK_THROWS_AS(Team{captain2},std::runtime_error);
CHECK_THROWS_AS(Team2{captain2},std::runtime_error);
}
TEST_CASE("Adding the same character to different teams") {
auto captain1 = create_tninja();
auto captain2 = create_oninja();
auto captain3 = create_yninja();
Team team1{captain1};
Team team2{captain2};
Team2 team3{captain3};
auto teammate1 = create_cowboy();
auto teammate2 = create_oninja();
team1.add(teammate1);
team1.add(teammate2);
CHECK_THROWS_AS(team2.add(teammate1),std::runtime_error);
CHECK_THROWS_AS(team3.add(teammate1),std::runtime_error);
CHECK_THROWS_AS(team2.add(teammate2),std::runtime_error);
CHECK_THROWS_AS(team3.add(teammate2),std::runtime_error);
}
}
TEST_SUITE("Battle related methods") {
TEST_CASE("Cowboy shoot() and reload() methods") {
auto cowboy = create_cowboy();
auto target = create_oninja();
auto shoot = [&](int times) {
for (int i = 0; i < times; i++) {
cowboy->shoot(target);
}
};
shoot(6);
CHECK_FALSE(cowboy->hasboolets());
CHECK_NOTHROW(cowboy->shoot(target)); // This should not damage the target
cowboy->reload();
shoot(2);
cowboy->reload();
shoot(6);
CHECK(target->isAlive()); // Target should still be alive with 10 hit points if the cowboys damage is 10
shoot(1);
CHECK(target->isAlive()); // Reloading when the magazine isn't empty shouldn't result in more than 6 bullets, the previous shoot should have no effect
cowboy->reload();
shoot(1);
CHECK_FALSE(target->isAlive()); // Target should be dead
delete cowboy;
delete target;
}
TEST_CASE("Ninjas hit points are different") {
auto old = create_oninja();
auto trained = create_tninja();
auto young = create_yninja();
auto cowboy = create_cowboy();
for (int i = 0; i < 15; i++) {
cowboy->reload();
// After 10 shots, young should die
if (i < 10) {
CHECK(young->isAlive());
cowboy->shoot(young);
}
// After 12 shots, trained should die
if (i < 12) {
CHECK(trained->isAlive());
cowboy->shoot(trained);
}
// Old should only die on the last iteration of the for loop
CHECK(old->isAlive());
cowboy->shoot(old);
}
CHECK_FALSE((old->isAlive() || young->isAlive() || trained->isAlive()));
delete old ;
delete trained ;
delete young ;
delete cowboy ;
}
TEST_CASE("Ninjas speeds are different") {
OldNinja old{"Bob", Point{random_float(0) + 15, random_float(0) + 15}};
TrainedNinja trained{"Kung fu panda", Point{random_float(0) + 15, random_float(0) + 15}};
YoungNinja young{"Karate kid", Point{random_float(0) + 15, random_float(0) + 15}};
Cowboy cowboy{"Clint", Point{0, 0}};
double old_distance = old.distance(&cowboy);
double young_distance = young.distance(&cowboy);
double trained_distance = trained.distance(&cowboy);
old.move(&cowboy);
trained.move(&cowboy);
young.move(&cowboy);
// The new distance should equal the old distance minus the speed of the specific ninja
CHECK_EQ(old.distance(&cowboy),
doctest::Approx(old_distance - 8).epsilon(0.001));
CHECK_EQ(trained.distance(&cowboy),
doctest::Approx(trained_distance - 12).epsilon(0.001));
CHECK_EQ(young.distance(&cowboy),
doctest::Approx(young_distance - 14).epsilon(0.001));
}
TEST_CASE("Ninjas can only slash when distance is less than 1") {
OldNinja old{"Bob", Point{0, 0}};
TrainedNinja trained{"Kung fu panda", Point{0, 0}};
YoungNinja young{"Karate kid", Point{0.5, 0.5}};
Cowboy cowboy{"Clint", Point{0.5, 0.5}};
for (int i = 0; i < 1; i++) {
old.slash(&cowboy);
young.slash(&cowboy);
}
CHECK(cowboy.isAlive());
old.slash(&cowboy);
CHECK_FALSE(cowboy.isAlive());
YoungNinja ninja{"Bob", Point{-0.5, 0.5}}; // Distance from young is exactly one
OldNinja ninja2{"Bob", Point{2, 2}};
// These attacks should have no affect
for (int i = 0; i < 20; i++) {
trained.slash(&ninja2);
old.slash(&ninja2);
young.slash(&ninja2);
}
for(int i = 0 ; i < 1 ; i++){
old.slash(&ninja);
young.slash(&ninja);
}
CHECK(ninja.isAlive());
CHECK(ninja2.isAlive());
}
TEST_CASE("Dead characters cannot attack and characters cannot attack a dead enemy") {
OldNinja old{"Bob", Point{0, 0}};
YoungNinja young{"Bob", Point{0, 0}};
Cowboy cowboy{"Bob", Point{0, 0}};
TrainedNinja trained("Bob", Point{0, 0});
OldNinja old2{"Bob", Point{0, 0}};
YoungNinja young2{"Bob", Point{0, 0}};
Cowboy cowboy2{"Bob", Point{0, 0}};
TrainedNinja trained2("Bob", Point{0, 0});
while (old2.isAlive()) {
young.slash(&old2);
}
while (young2.isAlive()) {
young.slash(&young2);
}
while (trained2.isAlive()) {
young.slash(&trained2);
}
while (cowboy2.isAlive()) {
young.slash(&cowboy2);
}
// Attacking a dead character
CHECK_THROWS_AS(young.slash(&old2), std::runtime_error);
CHECK_THROWS_AS(cowboy.shoot(&old2), std::runtime_error);
CHECK_THROWS_AS(trained.slash(&cowboy2), std::runtime_error);
CHECK_THROWS_AS(old.slash(&cowboy2), std::runtime_error);
// Calling the attacking method of a dead character
CHECK_THROWS_AS(young2.slash(&old), std::runtime_error);
CHECK_THROWS_AS(cowboy2.shoot(&old), std::runtime_error);
CHECK_THROWS_AS(trained2.slash(&cowboy), std::runtime_error);
CHECK_THROWS_AS(old2.slash(&cowboy), std::runtime_error);
}
TEST_CASE("Sending nullptr to the attack() method") {
auto cowboy = create_cowboy();
auto ninja = create_tninja();
Team team{cowboy};
Team2 team2{ninja};
CHECK_THROWS_AS(team.attack(nullptr), std::invalid_argument);
CHECK_THROWS_AS(team2.attack(nullptr), std::invalid_argument);
}
TEST_CASE("Sending negative value to hit()") {
auto cowboy = create_cowboy();
auto yninja = create_yninja();
auto oninja = create_oninja();
auto tninja = create_tninja();
CHECK_THROWS_AS(cowboy->hit(-random_float(1, 100)), std::invalid_argument);
CHECK_THROWS_AS(yninja->hit(-random_float(1, 100)), std::invalid_argument);
CHECK_THROWS_AS(oninja->hit(-random_float(1, 100)), std::invalid_argument);
CHECK_THROWS_AS(tninja->hit(-random_float(1, 100)), std::invalid_argument);
delete cowboy;
delete yninja;
delete oninja;
delete tninja;
}
TEST_CASE("Dead cowboy can not reload") {
auto cowboy = create_cowboy();
auto cowboy2 = create_cowboy();
cowboy->shoot(cowboy2);
while (cowboy2->isAlive()) {
cowboy->shoot(cowboy2);
cowboy->reload();
}
CHECK_THROWS_AS(cowboy2->reload(), std::runtime_error);
delete cowboy;
delete cowboy2;
}
TEST_CASE("No self harm") {
auto cowboy = create_cowboy();
auto yninja = create_yninja();
auto oninja = create_oninja();
auto tninja = create_tninja();
CHECK_THROWS_AS(cowboy->shoot(cowboy), std::runtime_error);
CHECK_THROWS_AS(yninja->slash(yninja), std::runtime_error);
CHECK_THROWS_AS(oninja->slash(oninja), std::runtime_error);
CHECK_THROWS_AS(tninja->slash(tninja), std::runtime_error);
delete cowboy;
delete yninja;
delete oninja;
delete tninja;
}
}
TEST_SUITE("Battle simulations") {
auto multi_attack = [](int n, Team &attacker, Team &defender) {
for (int i = 0; i < n; i++) {
if (defender.stillAlive()) {
attacker.attack(&defender);
}
}
};
TEST_CASE("Characters attack the closest enemy to the captain and ignore dead enemies ") {
Team team{create_cowboy(-1, -1)};
team.add(create_yninja(0, 0));
team.add(create_oninja(-0.5, -0.5));
team.add(create_tninja(0.5, 0.5));
team.add(create_cowboy());
CHECK_EQ(team.stillAlive(), 5);
auto young_ninja = create_yninja(0, 0);
auto trained_ninja = create_tninja(1, 1);
auto old_ninja = create_oninja(2, 2);
auto young_ninja2 = create_yninja(3, 3);
auto cowboy = create_cowboy(-6, -6);
auto cowboy2 = create_cowboy(-7, -7);
auto cowboy3 = create_cowboy(-8, -8);
Team team2{young_ninja};
team2.add(trained_ninja);
team2.add(old_ninja);
team2.add(young_ninja2);
team2.add(cowboy);
team2.add(cowboy2);
team2.add(cowboy3);
CHECK_EQ(team2.stillAlive(), 7);
multi_attack(2, team, team2);
CHECK_FALSE(young_ninja->isAlive()); // Young ninja should be dead
CHECK((trained_ninja->isAlive() && old_ninja->isAlive() &&
young_ninja2->isAlive())); // Everyone else should still be alive
team.attack(&team2);
CHECK((!trained_ninja->isAlive() && old_ninja->isAlive() &&
young_ninja2->isAlive())); // No one should die in the attack
multi_attack(2, team, team2);
CHECK_FALSE(trained_ninja->isAlive()); // Trained ninja should be dead
CHECK((!old_ninja->isAlive() && young_ninja2->isAlive()));
multi_attack(4, team, team2);
CHECK_FALSE(old_ninja->isAlive()); // Old ninja should be dead
CHECK(!young_ninja2->isAlive());
multi_attack(2, team, team2);
CHECK_NOTHROW(team.attack(
&team2)); // The entire enemy team will be dead before every cowboy shoots, the attack should stop and not throw an exception
CHECK_FALSE(young_ninja2->isAlive()); // Young ninja should be dead
CHECK_THROWS_AS(team.attack(&team2), std::runtime_error); // Attacking a dead team should throw an exception
}
/*
* In this test only cowboys are used because they are stationary. This allows us to better keep track of everyone's position to better test for captains assignment.
* The characters are organized as such:
* 2-1--2-[C1]-[C2]--2--1
* A hyphen (-) denotes a distance of one.
* */
TEST_CASE("The closest teammate to the captain is appointed as captain") {
auto team_c1 = create_cowboy(0, 0);
auto team2_c1 = create_cowboy(-2, 0);
auto team_c2 = create_cowboy(-3, 0);
auto team2_c2 = create_cowboy(1, 0);//
auto team2_c3 = create_cowboy(3, 0);//
auto team_c3 = create_cowboy(5, 0);//
auto team2_c4 = create_cowboy(-5, 0);
Team team1{team_c1};
team1.add(team_c2);
team1.add(team_c3);
Team2 team2{team2_c2};
team2.add(team2_c1);
team2.add(team2_c3);
team2.add(team2_c4);
multi_attack(4, team1, team2);
// The captain of team2 is the closest enemy to the captain of team1, and therefore should be dead.
CHECK((!team2_c2->isAlive() && team2_c1->isAlive() && team2_c3->isAlive() && team2_c4->isAlive()));
// At this point, the captain should be team2_c3; hence, the next enemy to be attacked by team2 should team_c3.
multi_attack(6, team2, team1);
CHECK((!team_c3->isAlive() && team_c1->isAlive() && team_c2->isAlive()));
// Killing the new captain
while (team2_c3->isAlive()) {
team_c1->reload();
team_c1->shoot(team2_c3);
}
CHECK((!team2_c2->isAlive() && team2_c1->isAlive() && !team2_c3->isAlive() && team2_c4->isAlive()));
//Next captain should be team2_c1, hence, the next enemy to be attacked by team2 should team_cc.
multi_attack(7, team2, team1);
CHECK((!team_c3->isAlive() && team_c1->isAlive() && !team_c2->isAlive()));
while (team1.stillAlive() && team2.stillAlive()) {
team1.attack(&team2);
team2.attack(&team1);
}
}
// In this test the attacking team is again composed of cowboys, this is because cowboys are stationary, and we can better predict the damage done in every attack.
TEST_CASE("If several enemies are equidistant from the captain, only a single enemy should still be targeted.") {
auto cowboy = create_cowboy();
Team team{cowboy};
for (int i = 0; i < 4; i++) {
team.add(create_cowboy());
}
auto char1 = create_yninja(0, 0);
auto char2 = create_yninja(0, 0);
auto char3 = create_yninja(0, 0);
auto char4 = create_yninja(0, 0);
Team team2{char1};
team2.add(char2);
team2.add(char3);
team2.add(char4);
// Young ninjas have 100 hit points. 2 attacks should result in 10 shots, killing only one, if they all target the same enemy
multi_attack(2, team, team2);
CHECK_EQ(team2.stillAlive(), 3);
// Two more attacks should result in another single casualty
multi_attack(2, team, team2);
CHECK_EQ(team2.stillAlive(), 2);
// Two more attacks should result in another single casualty
multi_attack(2, team, team2);
CHECK_EQ(team2.stillAlive(), 1);
//The cowboys should need to reload, hence three attacks are needed
multi_attack(3, team, team2);
CHECK_EQ(team2.stillAlive(), 0);
}
// Similar to the previous test, only this time the captain is mobile.
TEST_CASE("When the captain moves, a different enemy should be targeted") {
auto t11 = create_yninja(random_float(1.5, 1.6), random_float(1.5, 1.6));
auto t12 = create_oninja(random_float(2.5, 2.6), random_float(2.7, 2.5));
auto t13 = create_tninja(random_float(3.5, 3.6), random_float(3.5, 3.6));
auto t14 = create_cowboy();
Team team{t11};
team.add(t12);
team.add(t13);
team.add(t14);
auto t21 = create_cowboy(random_float(-1.5, -1.5), random_float(-1.5, -1.6));
auto t22 = create_tninja(random_float(-2.5, -2.6), random_float(-2.5, -2.6));
auto t23 = create_yninja(random_float(-3.5, -3.6), random_float(-3.5, -3.6));
Team team2{t21};
team2.add(t22);
team2.add(t23);
team.attack(&team2);
CHECK_EQ(t11->distance(t21), doctest::Approx(0).epsilon(0.001));
CHECK_EQ(t12->distance(t21), doctest::Approx(0).epsilon(0.001));
CHECK_EQ(t13->distance(t21), doctest::Approx(0).epsilon(0.001));
CHECK(t21->isAlive());
multi_attack(3, team, team2);
CHECK_FALSE(t21->isAlive()); // The first move in the attack should be a shot by the cowboy that kills t21
// After the cowboy kills t21, all the ninja should move towards t22.
CHECK_EQ(t11->distance(t22), doctest::Approx(0).epsilon(0.001));
CHECK_EQ(t12->distance(t22), doctest::Approx(0).epsilon(0.001));
CHECK_EQ(t13->distance(t22), doctest::Approx(0).epsilon(0.001));
// Moving the captain behind t23, making t23 the new closest enemy.
Cowboy decoy{"decoy", Point{-5, -5}};
decoy.shoot(t23); //A shot needed to kill t23 in the next attack without making the ninjas move to next target
t11->move(&decoy);
multi_attack(3, team, team2);
CHECK_EQ(t11->distance(t23), doctest::Approx(0).epsilon(0.001));
CHECK_EQ(t12->distance(t23), doctest::Approx(0).epsilon(0.001));
CHECK_EQ(t13->distance(t23), doctest::Approx(0).epsilon(0.001));
CHECK((!t21->isAlive() && !t22->isAlive() && !t23->isAlive()));
CHECK_NOTHROW(simulate_battle(team, team2));
}
TEST_CASE("Run full battles using random_char to ensure full functionality") {
SUBCASE("Team vs Team") {
Team team{random_char()};
Team team2{random_char()};
for (int i = 0; i < MAX_TEAM - 1; i++) {
team.add(random_char());
team2.add(random_char());
}
simulate_battle(team, team2);
CHECK(((team.stillAlive() && !team2.stillAlive()) || (!team.stillAlive() && team2.stillAlive())));
}
SUBCASE("Team vs Team2") {
Team team{random_char()};
Team2 team2{random_char()};
for (int i = 0; i < MAX_TEAM - 1; i++) {
team.add(random_char());
team2.add(random_char());
}
simulate_battle(team, team2);
CHECK(((team.stillAlive() && !team2.stillAlive()) || (!team.stillAlive() && team2.stillAlive())));
}
SUBCASE("Team2 vs Team2") {
Team2 team{random_char()};
Team2 team2{random_char()};
for (int i = 0; i < MAX_TEAM - 1; i++) {
team.add(random_char());
team2.add(random_char());
}
simulate_battle(team, team2);
CHECK(((team.stillAlive() && !team2.stillAlive()) || (!team.stillAlive() && team2.stillAlive())));
}
}
}