dos-vga-arena-shooter-game/spawn_test.c

83 lines
2.4 KiB
C
Raw Normal View History

2024-02-28 17:50:57 +00:00
#include <stdlib.h>
#include "cutest-1.5/CuTest.h"
#include "movement.h"
#include "game.h"
#include "spawn.h"
#include "movement.h"
// testing these private methods, i know
void selectEnemySpawnLocation(
struct EnemySpawningDetails *spawnDetails,
struct RabbitPosition *rabbitPosition
);
int determineEnemyHitPointCalculation(int difficulty, int pcnt);
int spawnEnemy(struct EnemySpawningDetails*, struct GlobalGameState*);
struct EnemySpawningDetails spawnDetails;
struct RabbitPosition rabbitPosition;
struct GlobalGameState globalGameState;
struct EnemyPosition enemyPosition;
void TestSelectEnemySpawnLocation(CuTest *tc) {
srand(1);
spawnDetails.gate = -1;
spawnDetails.spawnX = -1;
spawnDetails.spawnY = -1;
rabbitPosition.mouseAngle = 30;
selectEnemySpawnLocation(
&spawnDetails,
&rabbitPosition
);
// built from setting seed to 1
CuAssertIntEquals(tc, 3, spawnDetails.gate);
CuAssertIntEquals(tc, 27, spawnDetails.spawnX);
CuAssertIntEquals(tc, 91, spawnDetails.spawnY);
}
void TestDetermineEnemyHitPointCalculation(CuTest *tc) {
srand(1);
CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(0, 0));
CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(0, 3));
CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(2, 0));
CuAssertIntEquals(tc, 1, determineEnemyHitPointCalculation(2, 2));
CuAssertIntEquals(tc, 2, determineEnemyHitPointCalculation(2, 3));
}
void TestSpawnEnemy(CuTest *tc) {
srand(1);
spawnDetails.gate = 1;
spawnDetails.spawnX = 100;
spawnDetails.spawnY = 50;
spawnDetails.enemyPosition = &enemyPosition;
globalGameState.difficulty = 4;
spawnEnemy(&spawnDetails, &globalGameState);
// randomized values
CuAssertIntEquals(tc, 2, enemyPosition.hitPoints);
CuAssertIntEquals(tc, 103, enemyPosition.enemyFireDelayStep);
// from spawndetails
CuAssertIntEquals(tc, 1, enemyPosition.gateExitedFrom);
CuAssertIntEquals(tc, 100, enemyPosition.enemyPosition[0]);
CuAssertIntEquals(tc, 50, enemyPosition.enemyPosition[1]);
CuAssertIntEquals(tc, 100, enemyPosition.oldEnemyPosition[0]);
CuAssertIntEquals(tc, 50, enemyPosition.oldEnemyPosition[1]);
}
CuSuite *SpawnGetSuite() {
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, TestSelectEnemySpawnLocation);
SUITE_ADD_TEST(suite, TestDetermineEnemyHitPointCalculation);
SUITE_ADD_TEST(suite, TestSpawnEnemy);
return suite;
}