2024-03-01 02:29:23 +00:00
|
|
|
#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);
|
|
|
|
|
2024-03-04 22:38:03 +00:00
|
|
|
CuAssertIntEquals(tc, 18, determinePowerupCooldownTime(0));
|
|
|
|
CuAssertIntEquals(tc, 28, determinePowerupCooldownTime(1));
|
|
|
|
CuAssertIntEquals(tc, 33, determinePowerupCooldownTime(2));
|
2024-03-01 02:29:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-02 01:40:51 +00:00
|
|
|
void TestDetermineWeaponRounds(CuTest *tc) {
|
2024-03-01 02:29:23 +00:00
|
|
|
srand(1);
|
|
|
|
|
2024-03-04 22:38:03 +00:00
|
|
|
CuAssertIntEquals(tc, 10, determineWeaponRounds(0));
|
|
|
|
CuAssertIntEquals(tc, 23, determineWeaponRounds(1));
|
|
|
|
CuAssertIntEquals(tc, 36, determineWeaponRounds(2));
|
2024-03-01 02:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
2024-03-04 22:38:03 +00:00
|
|
|
CuAssertIntEquals(tc, 90, playerPowerup.cooldown);
|
2024-03-01 02:29:23 +00:00
|
|
|
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
|
2024-03-04 22:38:03 +00:00
|
|
|
CuAssertIntEquals(tc, 15, playerPowerup.cooldown);
|
2024-03-01 02:29:23 +00:00
|
|
|
CuAssertIntEquals(tc, 58, playerPowerup.x);
|
|
|
|
CuAssertIntEquals(tc, 178, playerPowerup.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *PowerupGetSuite() {
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, TestDeterminePowerupCooldownTime);
|
2024-03-02 01:40:51 +00:00
|
|
|
SUITE_ADD_TEST(suite, TestDetermineWeaponRounds);
|
2024-03-01 02:29:23 +00:00
|
|
|
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;
|
|
|
|
}
|