160 lines
4.2 KiB
C
160 lines
4.2 KiB
C
#include "cutest-1.5/CuTest.h"
|
|
#include "combat.h"
|
|
|
|
#include "game.h"
|
|
#include "movement.h"
|
|
#include "const.h"
|
|
#include "powerup.h"
|
|
|
|
int processEnemyKillStates(struct EnemyPosition[]);
|
|
|
|
void TestProcessEmenyKillStates(CuTest *tc) {
|
|
struct EnemyPosition enemyPosition[ENEMY_MAX_COUNT];
|
|
int i, result;
|
|
|
|
for (i = 0; i < ENEMY_MAX_COUNT; ++i) {
|
|
enemyPosition[i].wasKilled = 0;
|
|
}
|
|
|
|
enemyPosition[0].wasKilled = 1;
|
|
enemyPosition[ENEMY_MAX_COUNT - 1].wasKilled = 1;
|
|
|
|
result = processEnemyKillStates(enemyPosition);
|
|
|
|
CuAssertIntEquals(tc, 2, result);
|
|
}
|
|
|
|
void TestFireCurrentWeaponOnce_NoRoundsRemaining(CuTest *tc) {
|
|
struct RabbitWeaponry rabbitWeaponry;
|
|
|
|
rabbitWeaponry.currentWeaponRemainingRounds = 0;
|
|
rabbitWeaponry.currentWeapon = 99;
|
|
|
|
fireCurrentWeaponOnce(&rabbitWeaponry);
|
|
|
|
CuAssertIntEquals(tc, 99, rabbitWeaponry.currentWeapon);
|
|
CuAssertIntEquals(tc, 0, rabbitWeaponry.currentWeaponRemainingRounds);
|
|
}
|
|
|
|
void TestFireCurrentWeaponOnce_OneRoundRemaining(CuTest *tc) {
|
|
struct RabbitWeaponry rabbitWeaponry;
|
|
|
|
rabbitWeaponry.currentWeaponRemainingRounds = 1;
|
|
rabbitWeaponry.currentWeapon = 99;
|
|
|
|
fireCurrentWeaponOnce(&rabbitWeaponry);
|
|
|
|
CuAssertIntEquals(tc, WEAPON_TYPE_SINGLE_SHOT_GUN, rabbitWeaponry.currentWeapon);
|
|
CuAssertIntEquals(tc, 0, rabbitWeaponry.currentWeaponRemainingRounds);
|
|
}
|
|
|
|
void TestFireCurrentWeaponOnce_TwoRoundsRemaining(CuTest *tc) {
|
|
struct RabbitWeaponry rabbitWeaponry;
|
|
|
|
rabbitWeaponry.currentWeaponRemainingRounds = 2;
|
|
rabbitWeaponry.currentWeapon = 99;
|
|
|
|
fireCurrentWeaponOnce(&rabbitWeaponry);
|
|
|
|
CuAssertIntEquals(tc, 99, rabbitWeaponry.currentWeapon);
|
|
CuAssertIntEquals(tc, 1, rabbitWeaponry.currentWeaponRemainingRounds);
|
|
}
|
|
|
|
void TestMaybeFireShotCount_NotOK(CuTest *tc) {
|
|
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
|
|
int availableBullets[1] = { -1 };
|
|
int i, result;
|
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
rabbitBulletPosition[i].isActive = 1;
|
|
}
|
|
|
|
result = maybeFireShotCount(
|
|
rabbitBulletPosition,
|
|
availableBullets,
|
|
1
|
|
);
|
|
|
|
CuAssertIntEquals(tc, 0, result);
|
|
CuAssertIntEquals(tc, availableBullets[0], -1);
|
|
}
|
|
|
|
void TestMaybeFireShotCount_OK(CuTest *tc) {
|
|
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
|
|
int availableBullets[1] = { -1 };
|
|
int i, result;
|
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
rabbitBulletPosition[i].isActive = 1;
|
|
}
|
|
|
|
rabbitBulletPosition[4].isActive = 0;
|
|
|
|
result = maybeFireShotCount(
|
|
rabbitBulletPosition,
|
|
availableBullets,
|
|
1
|
|
);
|
|
|
|
CuAssertIntEquals(tc, 1, result);
|
|
CuAssertIntEquals(tc, availableBullets[0], 4);
|
|
}
|
|
|
|
void TestMaybeFireShotCount_NotEnoughAvailable(CuTest *tc) {
|
|
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
|
|
int availableBullets[2] = { -1, -1 };
|
|
int i, result;
|
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
rabbitBulletPosition[i].isActive = 1;
|
|
}
|
|
|
|
rabbitBulletPosition[4].isActive = 0;
|
|
|
|
result = maybeFireShotCount(
|
|
rabbitBulletPosition,
|
|
availableBullets,
|
|
2
|
|
);
|
|
|
|
CuAssertIntEquals(tc, 0, result);
|
|
CuAssertIntEquals(tc, 4, availableBullets[0]);
|
|
CuAssertIntEquals(tc, -1, availableBullets[1]);
|
|
}
|
|
|
|
void TestMaybeFireShotCount_EnoughAvailable(CuTest *tc) {
|
|
struct BulletPosition rabbitBulletPosition[RABBIT_BULLET_LIMIT];
|
|
int availableBullets[2] = { -1, -1 };
|
|
int i, result;
|
|
|
|
for (i = 0; i < RABBIT_BULLET_LIMIT; ++i) {
|
|
rabbitBulletPosition[i].isActive = 1;
|
|
}
|
|
|
|
rabbitBulletPosition[4].isActive = 0;
|
|
rabbitBulletPosition[6].isActive = 0;
|
|
|
|
result = maybeFireShotCount(
|
|
rabbitBulletPosition,
|
|
availableBullets,
|
|
2
|
|
);
|
|
|
|
CuAssertIntEquals(tc, 1, result);
|
|
CuAssertIntEquals(tc, 4, availableBullets[0]);
|
|
CuAssertIntEquals(tc, 6, availableBullets[1]);
|
|
}
|
|
|
|
CuSuite *CombatGetSuite() {
|
|
CuSuite *suite = CuSuiteNew();
|
|
SUITE_ADD_TEST(suite, TestProcessEmenyKillStates);
|
|
SUITE_ADD_TEST(suite, TestFireCurrentWeaponOnce_NoRoundsRemaining);
|
|
SUITE_ADD_TEST(suite, TestFireCurrentWeaponOnce_OneRoundRemaining);
|
|
SUITE_ADD_TEST(suite, TestFireCurrentWeaponOnce_TwoRoundsRemaining);
|
|
SUITE_ADD_TEST(suite, TestMaybeFireShotCount_NotOK);
|
|
SUITE_ADD_TEST(suite, TestMaybeFireShotCount_OK);
|
|
SUITE_ADD_TEST(suite, TestMaybeFireShotCount_NotEnoughAvailable);
|
|
SUITE_ADD_TEST(suite, TestMaybeFireShotCount_EnoughAvailable);
|
|
return suite;
|
|
}
|