summaryrefslogtreecommitdiff
path: root/tests/logicTests.cpp
blob: 97d9ed9cd5fe52d3798a809932465cf4adb7f6e7 (plain)
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
/** @file logicTests.cpp
* @brief Unit tests for the logic layer of a Rally-X game.
*
* The classes used to run Allegro's install and uninstall functions were tested indirectly
* through the use of other classes. If the AllegroWrappers classes are not working, they will
* result in tests failing, or the program crashing.
*
* The Car class's movement is tested through implementing a subclass of Car, PlayerCar, facing
* in a given direction with and without maze walls in the way, and testing its position after
* a frame has passed.
*
* The counting system with the Checkpoint class is tested through repeated creation and
* destruction of Checkpoint objects.
*
* The CollisionDetecter class is tested by setting up situations with each type of collision,
* and checking that they have the desired results on the objects involved.
*
* The DestroyedObjectPopup class is tested to ensure that it lasts the desired amount of time
* before being destroyed.
*
* The intelligence of the EnemyCar class is not unit tested, as it may change as extra states
* and AI schemes are implemented, possibly including a random element. Therefore, it should be
* tested manually by playing example levels and monitoring if the enemies appear to behave in
* a manner that makes gameplay interesting.
*
* The Game class is not tested directly. It pulls all of the units being tested together into
* a complete game, and so should be tested by running the Game.
*
* The GameObject class is tested indirectly through testing its subclasses.
*
* The LimitedTimeObject class is tested indirectly through the DestroyedObjectPopup and Smokescreen classes.
*
* The Maze class is tested in terms of its ability to construct itself correctly from a list of
* coordinates. It is also tested with the PlayerCar class where the movement of the PlayerCar is
* tested in a Maze.
*
* The MazeMath class is tested by running each of its functions with expected input and output values.
*
* The PlayerCar class is tested on its ability to move correctly as part of the tests for the Car class.
* The functioning of the PlayerCar's petrol system is also tested. Controlling of the PlayerCar
* is not tested, and should be tested manually by running the game and verifying that the arrow keys
* cause the direction of the PlayerCar to change appropriately. Further, the creation of Smokescreens
* by pressing the spacebar should also be tested manually.
*
* The Rock class only has functionality in collisions, and so is tested through the CollisionDetector's
* tests.
*
* The Smokescreen class is tested in that it disappears after a set time. Its affect on the EnemyCar class
* is tested through the CollisionDetector's tests.
*
* @author Justin Wernick
* @author David Schneider
*/

#include <vector>
#include <list>
#include <utility>
using namespace std;

#include <gtest/gtest.h>

#include "../source/logic/CollisionDetector.h"
#include "../source/logic/PlayerCar.h"
#include "../source/logic/EnemyCar.h"
#include "../source/logic/Checkpoint.h"
#include "../source/logic/Rock.h"
#include "../source/logic/Smokescreen.h"
#include "../source/logic/Maze.h"
#include "../source/logic/MazeMath.h"
#include "../source/logic/DestroyedObjectPopup.h"

/**
* @brief Tests that PlayerCar moves the correct amount in the up direction on each frame without obstacles.
*/
TEST(Car, updateMovesPlayerUpInEmptyMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(2,2,Maze::UP);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 2;
    double expectY = 2-player.speed();
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}

/**
* @brief Tests that PlayerCar moves the correct amount in the down direction on each frame without obstacles.
*/
TEST(Car, updateMovesPlayerDownInEmptyMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(2,2,Maze::DOWN);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 2;
    double expectY = 2+player.speed();
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}

/**
* @brief Tests that PlayerCar moves the correct amount in the left direction on each frame without obstacles.
*/
TEST(Car, updateMovesPlayerLeftInEmptyMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(2,2,Maze::LEFT);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 2-player.speed();
    double expectY = 2;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}

/**
* @brief Tests that PlayerCar moves the correct amount in the right direction on each frame without obstacles.
*/
TEST(Car, updateMovesPlayerRightInEmptyMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(2,2,Maze::RIGHT);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 2+player.speed();
    double expectY = 2;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}

/**
* @brief Tests that PlayerCar does not move up if the path is blocked.
*/
TEST(Car, carNotMovedWhenPathUpBlocked)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    walls.push_back(make_pair(3,3));
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(3,4,Maze::UP);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 3;
    double expectY = 4;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}
/**
* @brief Tests that PlayerCar does not move down if the path is blocked.
*/
TEST(Car, carNotMovedWhenPathDownBlocked)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    walls.push_back(make_pair(3,3));
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(3,2,Maze::DOWN);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 3;
    double expectY = 2;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}
/**
* @brief Tests that PlayerCar does not move left if the path is blocked.
*/
TEST(Car, carNotMovedWhenPathLeftBlocked)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    walls.push_back(make_pair(3,3));
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(4,3,Maze::LEFT);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 4;
    double expectY = 3;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}
/**
* @brief Tests that PlayerCar does not move right if the path is blocked.
*/
TEST(Car, carNotMovedWhenPathRightBlocked)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    walls.push_back(make_pair(3,3));
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(2,3,Maze::RIGHT);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 2;
    double expectY = 3;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}

/**
* @brief Tests that PlayerCar does not move up if currently on the top row of the maze.
*/
TEST(Car, carDoesNotMoveUpOutMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(3,0,Maze::UP);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 3;
    double expectY = 0;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}
/**
* @brief Tests that PlayerCar does not move down if currently on the bottom row of the maze.
*/
TEST(Car, carDoesNotMoveDownOutMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(3,5,Maze::DOWN);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 3;
    double expectY = 5;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}
/**
* @brief Tests that PlayerCar does not move left if currently on the first column of the maze.
*/
TEST(Car, carDoesNotMoveLeftOutMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(0,3,Maze::LEFT);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 0;
    double expectY = 3;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}
/**
* @brief Tests that PlayerCar does not move right if currently on the last column of the maze.
*/
TEST(Car, carDoesNotMoveRightOutMaze)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(5,3,Maze::RIGHT);

    list<Smokescreen> smokescreens;
    player.update(testMaze, smokescreens);

    double expectX = 5;
    double expectY = 3;
    EXPECT_FLOAT_EQ(expectX, player.x());
    EXPECT_FLOAT_EQ(expectY, player.y());
}

/**
* @brief Tests that counting of the number of checkpoints happens correctly.
*/
TEST(Checkpoint, countIncrementsAndDecrements)
{
    vector<Checkpoint> checkpoints;
    EXPECT_EQ(0, Checkpoint::checkpointCount());

    for (int i=0; i<1000; ++i)
    {
        checkpoints.push_back(Checkpoint(i,i));
    }
    EXPECT_EQ(1000, Checkpoint::checkpointCount());

    //brackets to limit scope
    {
        Checkpoint extraCheck1(0,0);
        Checkpoint extraCheck2 = extraCheck1;
        EXPECT_EQ(1002, Checkpoint::checkpointCount());
        extraCheck2 = extraCheck1;
        EXPECT_EQ(1002, Checkpoint::checkpointCount());
    }
    EXPECT_EQ(1000, Checkpoint::checkpointCount());

    while(!checkpoints.empty())
    {
        checkpoints.pop_back();
    }
    EXPECT_EQ(0, Checkpoint::checkpointCount());
}

/**
* @brief Tests that when a player and enemy overlap, both are marked for destruction.
*/
TEST(CollisionDetector, playerAndEnemyBothDestroyed)
{
    list<PlayerCar> players;
    list<EnemyCar> enemies;
    list<Checkpoint> checkpoints;
    list<Rock> rocks;
    list<Smokescreen> smokescreens;
    CollisionDetector detector;

    players.push_back(PlayerCar(5,5));
    players.push_back(PlayerCar(5,6));
    players.push_back(PlayerCar(6,5));
    players.push_back(PlayerCar(7,7.5));

    enemies.push_back(EnemyCar(5,6));
    enemies.push_back(EnemyCar(4,5));
    enemies.push_back(EnemyCar(6,6));
    enemies.push_back(EnemyCar(6.5,8));

    detector.checkCollisions(players, enemies, checkpoints, rocks, smokescreens);

    list<PlayerCar>::const_iterator playerIter = players.begin();
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_TRUE(playerIter->destroyed());
    ++playerIter;
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_TRUE(playerIter->destroyed());

    list<EnemyCar>::const_iterator enemyIter = enemies.begin();
    EXPECT_TRUE(enemyIter->destroyed());
    ++enemyIter;
    EXPECT_FALSE(enemyIter->destroyed());
    ++enemyIter;
    EXPECT_FALSE(enemyIter->destroyed());
    ++enemyIter;
    EXPECT_TRUE(enemyIter->destroyed());
}

/**
* @brief Tests that when a player and rock overlap, only the player is marked for destruction.
*/
TEST(CollisionDetector, playerDestroyedByRock)
{
    list<PlayerCar> players;
    list<EnemyCar> enemies;
    list<Checkpoint> checkpoints;
    list<Rock> rocks;
    list<Smokescreen> smokescreens;
    CollisionDetector detector;

    players.push_back(PlayerCar(5,5));
    players.push_back(PlayerCar(5,6));
    players.push_back(PlayerCar(6,5));
    players.push_back(PlayerCar(7,7.5));

    rocks.push_back(Rock(5,6));
    rocks.push_back(Rock(4,5));
    rocks.push_back(Rock(6,6));
    rocks.push_back(Rock(6.5,8));

    detector.checkCollisions(players, enemies, checkpoints, rocks, smokescreens);

    list<PlayerCar>::const_iterator playerIter = players.begin();
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_TRUE(playerIter->destroyed());
    ++playerIter;
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_TRUE(playerIter->destroyed());

    list<Rock>::const_iterator rockIter = rocks.begin();
    EXPECT_FALSE(rockIter->destroyed());
    ++rockIter;
    EXPECT_FALSE(rockIter->destroyed());
    ++rockIter;
    EXPECT_FALSE(rockIter->destroyed());
    ++rockIter;
    EXPECT_FALSE(rockIter->destroyed());
}

/**
* @brief Tests that when a player and checkpoint overlap, only the checkpoint is marked for destruction.
*/
TEST(CollisionDetector, checkpointDestroyedByPlayer)
{
    list<PlayerCar> players;
    list<EnemyCar> enemies;
    list<Checkpoint> checkpoints;
    list<Rock> rocks;
    list<Smokescreen> smokescreens;
    CollisionDetector detector;

    players.push_back(PlayerCar(5,5));
    players.push_back(PlayerCar(5,6));
    players.push_back(PlayerCar(6,5));
    players.push_back(PlayerCar(7,7.5));

    checkpoints.push_back(Checkpoint(5,6));
    checkpoints.push_back(Checkpoint(4,5));
    checkpoints.push_back(Checkpoint(6,6));
    checkpoints.push_back(Checkpoint(6.5,8));

    detector.checkCollisions(players, enemies, checkpoints, rocks, smokescreens);

    list<PlayerCar>::const_iterator playerIter = players.begin();
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_FALSE(playerIter->destroyed());
    ++playerIter;
    EXPECT_FALSE(playerIter->destroyed());

    list<Checkpoint>::const_iterator checkpointIter = checkpoints.begin();
    EXPECT_TRUE(checkpointIter->destroyed());
    ++checkpointIter;
    EXPECT_FALSE(checkpointIter->destroyed());
    ++checkpointIter;
    EXPECT_FALSE(checkpointIter->destroyed());
    ++checkpointIter;
    EXPECT_TRUE(checkpointIter->destroyed());
}

/**
* @brief Tests that when an enemy and smokescreen overlap, the enemy's speed becomes zero.
*/
TEST(CollisionDetector, enemyStoppedBySmokescreen)
{
    list<PlayerCar> players;
    list<EnemyCar> enemies;
    list<Checkpoint> checkpoints;
    list<Rock> rocks;
    list<Smokescreen> smokescreens;
    CollisionDetector detector;

    enemies.push_back(EnemyCar(5,5));
    enemies.push_back(EnemyCar(5,6));
    enemies.push_back(EnemyCar(6,5));
    enemies.push_back(EnemyCar(7,7.5));

    smokescreens.push_back(Smokescreen(5,6));
    smokescreens.push_back(Smokescreen(4,5));
    smokescreens.push_back(Smokescreen(6,6));
    smokescreens.push_back(Smokescreen(6.5,8));

    detector.checkCollisions(players, enemies, checkpoints, rocks, smokescreens);

    list<EnemyCar>::const_iterator enemyIter = enemies.begin();
    EXPECT_GT(enemyIter->speed(),0);
    ++enemyIter;
    EXPECT_FLOAT_EQ(0, enemyIter->speed());
    ++enemyIter;
    EXPECT_GT(enemyIter->speed(),0);
    ++enemyIter;
    EXPECT_FLOAT_EQ(0, enemyIter->speed());
}

/**
* @brief Tests that a DestroyedObjectPopup is destroyed 30 frames after it is created.
*/
TEST(DestroyedObjectPopup, destroyedAfterSetTime)
{
    DestroyedObjectPopup testPopup(3,2,BitmapStore::CRASHED_CAR);

    int i=0;
    while (!testPopup.destroyed())
    {
        testPopup.update();
        ++i;
    }

    EXPECT_EQ(30,i);
}

/**
* @brief Tests that the maze treats the undefined area outside its bounds as being walls.
*/
TEST(Maze, queryOutsideBoundsReturnsSolid)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    EXPECT_FALSE(testMaze.getSolid(5,5));
    EXPECT_FALSE(testMaze.getSolid(0,0));
    EXPECT_TRUE(testMaze.getSolid(6,5));
    EXPECT_TRUE(testMaze.getSolid(5,6));
    EXPECT_TRUE(testMaze.getSolid(-1,3));
    EXPECT_TRUE(testMaze.getSolid(3,-1));
}

/**
* @brief Tests that a maze can be generated without extending the width and height for objects.
*/
TEST(Maze, generationWithWallsWithoutObjectMax)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    walls.push_back(make_pair(1,2));
    walls.push_back(make_pair(4,3));
    testMaze.generateMaze(walls);

    //test random empty blocks
    EXPECT_FALSE(testMaze.getSolid(2,1));
    EXPECT_FALSE(testMaze.getSolid(0,0));

    //test wall blocks
    EXPECT_TRUE(testMaze.getSolid(1,2));
    EXPECT_TRUE(testMaze.getSolid(4,3));

    //test bounds are being set right
    EXPECT_TRUE(testMaze.getSolid(4,4));
    EXPECT_TRUE(testMaze.getSolid(5,3));
}

/**
* @brief Tests that a maze can be generated with extending the width and height for objects.
*/
TEST(Maze, generationWithWallsWithObjectMax)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    walls.push_back(make_pair(1,2));
    walls.push_back(make_pair(4,3));
    testMaze.generateMaze(walls,5,6);

    //test random empty blocks
    EXPECT_FALSE(testMaze.getSolid(2,1));
    EXPECT_FALSE(testMaze.getSolid(0,0));

    //test wall blocks
    EXPECT_TRUE(testMaze.getSolid(1,2));
    EXPECT_TRUE(testMaze.getSolid(4,3));

    //test bounds are being set right
    EXPECT_FALSE(testMaze.getSolid(4,4));
    EXPECT_FALSE(testMaze.getSolid(5,6));
    EXPECT_TRUE(testMaze.getSolid(6,6));
    EXPECT_TRUE(testMaze.getSolid(5,7));
}

/**
* @brief Tests that the formula for a straight line distance works as expected.
*/
TEST(MazeMath, distanceGivesExpectedResult)
{
    //right angle triange with sides of length 3, 4, and 5
    double x1 = 1;
    double y1 = 1;
    double x2 = 4;
    double y2 = 5;

    double expectedResult = 5;

    EXPECT_DOUBLE_EQ(expectedResult, MazeMath::distance(x1,y1,x2,y2));
}

/**
* @brief Tests that rounding off function works as expected.
*/
TEST(MazeMath, roundGivesExpectedResult)
{
    //right angle triange with sides of length 3, 4, and 5
    double roundUp = 5.5;
    double roundDown = 5.49;

    double expectUp = 6;
    double expectDown = 5;

    EXPECT_DOUBLE_EQ(expectUp, MazeMath::round(roundUp));
    EXPECT_DOUBLE_EQ(expectDown, MazeMath::round(roundDown));
}

/**
* @brief Tests that a PlayerCar can be created and destroyed repeatedly without incident.
*
* This tests that the PlayerCar can handle its own dependencies on Allegro, even when
* copy constructors are used (through vector).
*/
TEST(PlayerCar, creationAndDestructionCanHappen)
{
    EXPECT_NO_THROW({
        vector<PlayerCar> players;
        for (int i=0; i<10; ++i)
        {
            players.push_back(PlayerCar(i,i));
        }
        while(!players.empty())
        {
            players.pop_back();
        }
    });

    EXPECT_FALSE(al_is_system_installed());
}

/**
* @brief Tests that the player's petrol runs out, and that the player's speed is halved after that.
*
* Also tests that the speed is recovered if petrol is increased again.
*/
TEST(PlayerCar, playerSpeedAffectedByPetrol)
{
    Maze testMaze;
    vector<pair<int,int> > walls;
    testMaze.generateMaze(walls,5,5);

    PlayerCar player(5,3,Maze::RIGHT);

    list<Smokescreen> smokescreens;
    for (int i=0; i<1429; ++i)
    {
        player.update(testMaze, smokescreens);
    }

    EXPECT_FLOAT_EQ(0, player.petrol());
    EXPECT_FLOAT_EQ(0.05, player.speed());

    player.gotCheckpoint();
    EXPECT_GT(player.petrol(), 0);
    EXPECT_FLOAT_EQ(0.1, player.speed());
}

/**
* @brief Tests that a Smokescreen is destroyed 60 frames after it is created.
*/
TEST(Smokescreen, destroyedAfterSetTime)
{
    Smokescreen testSmokescreen(3,2);

    int i=0;
    while (!testSmokescreen.destroyed())
    {
        testSmokescreen.update();
        ++i;
    }

    EXPECT_EQ(60,i);
}