Rally X
ELEN3009 Project by Justin Wernick and David Schneider
Functions
tests/logicTests.cpp File Reference

Unit tests for the logic layer of a Rally-X game. More...

#include <vector>
#include <list>
#include <utility>
#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"

Go to the source code of this file.

Functions

 TEST (Car, updateMovesPlayerUpInEmptyMaze)
 Tests that PlayerCar moves the correct amount in the up direction on each frame without obstacles.
 TEST (Car, updateMovesPlayerDownInEmptyMaze)
 Tests that PlayerCar moves the correct amount in the down direction on each frame without obstacles.
 TEST (Car, updateMovesPlayerLeftInEmptyMaze)
 Tests that PlayerCar moves the correct amount in the left direction on each frame without obstacles.
 TEST (Car, updateMovesPlayerRightInEmptyMaze)
 Tests that PlayerCar moves the correct amount in the right direction on each frame without obstacles.
 TEST (Car, carNotMovedWhenPathUpBlocked)
 Tests that PlayerCar does not move up if the path is blocked.
 TEST (Car, carNotMovedWhenPathDownBlocked)
 Tests that PlayerCar does not move down if the path is blocked.
 TEST (Car, carNotMovedWhenPathLeftBlocked)
 Tests that PlayerCar does not move left if the path is blocked.
 TEST (Car, carNotMovedWhenPathRightBlocked)
 Tests that PlayerCar does not move right if the path is blocked.
 TEST (Car, carDoesNotMoveUpOutMaze)
 Tests that PlayerCar does not move up if currently on the top row of the maze.
 TEST (Car, carDoesNotMoveDownOutMaze)
 Tests that PlayerCar does not move down if currently on the bottom row of the maze.
 TEST (Car, carDoesNotMoveLeftOutMaze)
 Tests that PlayerCar does not move left if currently on the first column of the maze.
 TEST (Car, carDoesNotMoveRightOutMaze)
 Tests that PlayerCar does not move right if currently on the last column of the maze.
 TEST (Checkpoint, countIncrementsAndDecrements)
 Tests that counting of the number of checkpoints happens correctly.
 TEST (CollisionDetector, playerAndEnemyBothDestroyed)
 Tests that when a player and enemy overlap, both are marked for destruction.
 TEST (CollisionDetector, playerDestroyedByRock)
 Tests that when a player and rock overlap, only the player is marked for destruction.
 TEST (CollisionDetector, checkpointDestroyedByPlayer)
 Tests that when a player and checkpoint overlap, only the checkpoint is marked for destruction.
 TEST (CollisionDetector, enemyStoppedBySmokescreen)
 Tests that when an enemy and smokescreen overlap, the enemy's speed becomes zero.
 TEST (DestroyedObjectPopup, destroyedAfterSetTime)
 Tests that a DestroyedObjectPopup is destroyed 30 frames after it is created.
 TEST (Maze, queryOutsideBoundsReturnsSolid)
 Tests that the maze treats the undefined area outside its bounds as being walls.
 TEST (Maze, generationWithWallsWithoutObjectMax)
 Tests that a maze can be generated without extending the width and height for objects.
 TEST (Maze, generationWithWallsWithObjectMax)
 Tests that a maze can be generated with extending the width and height for objects.
 TEST (MazeMath, distanceGivesExpectedResult)
 Tests that the formula for a straight line distance works as expected.
 TEST (MazeMath, roundGivesExpectedResult)
 Tests that rounding off function works as expected.
 TEST (PlayerCar, creationAndDestructionCanHappen)
 Tests that a PlayerCar can be created and destroyed repeatedly without incident.
 TEST (PlayerCar, playerSpeedAffectedByPetrol)
 Tests that the player's petrol runs out, and that the player's speed is halved after that.
 TEST (Smokescreen, destroyedAfterSetTime)
 Tests that a Smokescreen is destroyed 60 frames after it is created.

Detailed Description

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
David Schneider

Definition in file logicTests.cpp.


Function Documentation

TEST ( Car  ,
updateMovesPlayerUpInEmptyMaze   
)

Tests that PlayerCar moves the correct amount in the up direction on each frame without obstacles.

Definition at line 75 of file logicTests.cpp.

TEST ( Car  ,
updateMovesPlayerDownInEmptyMaze   
)

Tests that PlayerCar moves the correct amount in the down direction on each frame without obstacles.

Definition at line 95 of file logicTests.cpp.

TEST ( Car  ,
updateMovesPlayerLeftInEmptyMaze   
)

Tests that PlayerCar moves the correct amount in the left direction on each frame without obstacles.

Definition at line 115 of file logicTests.cpp.

TEST ( Car  ,
updateMovesPlayerRightInEmptyMaze   
)

Tests that PlayerCar moves the correct amount in the right direction on each frame without obstacles.

Definition at line 135 of file logicTests.cpp.

TEST ( Car  ,
carNotMovedWhenPathUpBlocked   
)

Tests that PlayerCar does not move up if the path is blocked.

Definition at line 155 of file logicTests.cpp.

TEST ( Car  ,
carNotMovedWhenPathDownBlocked   
)

Tests that PlayerCar does not move down if the path is blocked.

Definition at line 175 of file logicTests.cpp.

TEST ( Car  ,
carNotMovedWhenPathLeftBlocked   
)

Tests that PlayerCar does not move left if the path is blocked.

Definition at line 195 of file logicTests.cpp.

TEST ( Car  ,
carNotMovedWhenPathRightBlocked   
)

Tests that PlayerCar does not move right if the path is blocked.

Definition at line 215 of file logicTests.cpp.

TEST ( Car  ,
carDoesNotMoveUpOutMaze   
)

Tests that PlayerCar does not move up if currently on the top row of the maze.

Definition at line 236 of file logicTests.cpp.

TEST ( Car  ,
carDoesNotMoveDownOutMaze   
)

Tests that PlayerCar does not move down if currently on the bottom row of the maze.

Definition at line 255 of file logicTests.cpp.

TEST ( Car  ,
carDoesNotMoveLeftOutMaze   
)

Tests that PlayerCar does not move left if currently on the first column of the maze.

Definition at line 274 of file logicTests.cpp.

TEST ( Car  ,
carDoesNotMoveRightOutMaze   
)

Tests that PlayerCar does not move right if currently on the last column of the maze.

Definition at line 293 of file logicTests.cpp.

TEST ( Checkpoint  ,
countIncrementsAndDecrements   
)

Tests that counting of the number of checkpoints happens correctly.

Definition at line 313 of file logicTests.cpp.

TEST ( CollisionDetector  ,
playerAndEnemyBothDestroyed   
)

Tests that when a player and enemy overlap, both are marked for destruction.

Definition at line 344 of file logicTests.cpp.

TEST ( CollisionDetector  ,
playerDestroyedByRock   
)

Tests that when a player and rock overlap, only the player is marked for destruction.

Definition at line 387 of file logicTests.cpp.

TEST ( CollisionDetector  ,
checkpointDestroyedByPlayer   
)

Tests that when a player and checkpoint overlap, only the checkpoint is marked for destruction.

Definition at line 430 of file logicTests.cpp.

TEST ( CollisionDetector  ,
enemyStoppedBySmokescreen   
)

Tests that when an enemy and smokescreen overlap, the enemy's speed becomes zero.

Definition at line 473 of file logicTests.cpp.

TEST ( DestroyedObjectPopup  ,
destroyedAfterSetTime   
)

Tests that a DestroyedObjectPopup is destroyed 30 frames after it is created.

Definition at line 507 of file logicTests.cpp.

TEST ( Maze  ,
queryOutsideBoundsReturnsSolid   
)

Tests that the maze treats the undefined area outside its bounds as being walls.

Definition at line 524 of file logicTests.cpp.

TEST ( Maze  ,
generationWithWallsWithoutObjectMax   
)

Tests that a maze can be generated without extending the width and height for objects.

Definition at line 541 of file logicTests.cpp.

TEST ( Maze  ,
generationWithWallsWithObjectMax   
)

Tests that a maze can be generated with extending the width and height for objects.

Definition at line 565 of file logicTests.cpp.

TEST ( MazeMath  ,
distanceGivesExpectedResult   
)

Tests that the formula for a straight line distance works as expected.

Definition at line 591 of file logicTests.cpp.

TEST ( MazeMath  ,
roundGivesExpectedResult   
)

Tests that rounding off function works as expected.

Definition at line 607 of file logicTests.cpp.

TEST ( PlayerCar  ,
creationAndDestructionCanHappen   
)

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).

Definition at line 626 of file logicTests.cpp.

TEST ( PlayerCar  ,
playerSpeedAffectedByPetrol   
)

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.

Definition at line 648 of file logicTests.cpp.

TEST ( Smokescreen  ,
destroyedAfterSetTime   
)

Tests that a Smokescreen is destroyed 60 frames after it is created.

Definition at line 673 of file logicTests.cpp.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator