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

126 lines
3.2 KiB
C

#include "cutest-1.5/CuTest.h"
#include <stdio.h>
#include <stdlib.h>
#include "game.h"
#include "movement.h"
#include "powerup.h"
#include "const.h"
void TestDeterminePowerupCooldownTime(CuTest *tc) {
srand(1);
CuAssertIntEquals(tc, 18, determinePowerupCooldownTime(0));
CuAssertIntEquals(tc, 25, determinePowerupCooldownTime(1));
CuAssertIntEquals(tc, 81, determinePowerupCooldownTime(2));
}
void TestDetermineShotgunRounds(CuTest *tc) {
srand(1);
CuAssertIntEquals(tc, 18, determineShotgunRounds(0));
CuAssertIntEquals(tc, 39, determineShotgunRounds(1));
CuAssertIntEquals(tc, 81, determineShotgunRounds(2));
}
void TestProcessPowerupCooldown_PowerupActive(CuTest *tc) {
struct PlayerPowerup playerPowerup;
struct GlobalGameState globalGameState;
struct RabbitWeaponry rabbitWeaponry;
playerPowerup.isActive = 1;
playerPowerup.cooldown = 100;
processPowerupCooldown(
&playerPowerup,
&globalGameState,
&rabbitWeaponry,
10
);
CuAssertIntEquals(tc, 100, playerPowerup.cooldown);
CuAssertIntEquals(tc, 1, playerPowerup.isActive);
}
void TestProcessPowerupCooldown_WeaponActive(CuTest *tc) {
struct PlayerPowerup playerPowerup;
struct GlobalGameState globalGameState;
struct RabbitWeaponry rabbitWeaponry;
playerPowerup.isActive = 0;
playerPowerup.cooldown = 100;
rabbitWeaponry.currentWeapon = 99;
processPowerupCooldown(
&playerPowerup,
&globalGameState,
&rabbitWeaponry,
10
);
CuAssertIntEquals(tc, 100, playerPowerup.cooldown);
CuAssertIntEquals(tc, 0, playerPowerup.isActive);
}
void TestProcessPowerupCooldown_NotTriggered(CuTest *tc) {
struct PlayerPowerup playerPowerup;
struct GlobalGameState globalGameState;
struct RabbitWeaponry rabbitWeaponry;
playerPowerup.isActive = 0;
playerPowerup.cooldown = 100;
rabbitWeaponry.currentWeapon = WEAPON_TYPE_SINGLE_SHOT_GUN;
processPowerupCooldown(
&playerPowerup,
&globalGameState,
&rabbitWeaponry,
10
);
CuAssertIntEquals(tc, 90, playerPowerup.cooldown);
CuAssertIntEquals(tc, 0, playerPowerup.isActive);
}
void TestProcessPowerupCooldown_Triggered(CuTest *tc) {
struct PlayerPowerup playerPowerup;
struct GlobalGameState globalGameState;
struct RabbitWeaponry rabbitWeaponry;
srand(1);
playerPowerup.isActive = 0;
playerPowerup.cooldown = 100;
rabbitWeaponry.currentWeapon = WEAPON_TYPE_SINGLE_SHOT_GUN;
playerPowerup.willBeInactive = 1;
globalGameState.difficulty = 0;
processPowerupCooldown(
&playerPowerup,
&globalGameState,
&rabbitWeaponry,
101
);
CuAssertIntEquals(tc, 1, playerPowerup.isActive);
CuAssertIntEquals(tc, 0, playerPowerup.willBeInactive);
// rand
CuAssertIntEquals(tc, 13, playerPowerup.cooldown);
CuAssertIntEquals(tc, 58, playerPowerup.x);
CuAssertIntEquals(tc, 178, playerPowerup.y);
}
CuSuite *PowerupGetSuite() {
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, TestDeterminePowerupCooldownTime);
SUITE_ADD_TEST(suite, TestDetermineShotgunRounds);
SUITE_ADD_TEST(suite, TestProcessPowerupCooldown_PowerupActive);
SUITE_ADD_TEST(suite, TestProcessPowerupCooldown_WeaponActive);
SUITE_ADD_TEST(suite, TestProcessPowerupCooldown_NotTriggered);
SUITE_ADD_TEST(suite, TestProcessPowerupCooldown_Triggered);
return suite;
}