Refactor ability use skills to be testable. Add in basic player damage check and ability use unit tests.

This commit is contained in:
2024-06-24 12:04:06 -05:00
parent f355b01171
commit d6d02cc986
10 changed files with 149 additions and 49 deletions
@@ -37,6 +37,7 @@ All rights reserved.
#pragma endregion
#include "CppUnitTest.h"
#include "AdventuresInLestoria.h"
#include "Tutorial.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace olc::utils;
@@ -46,6 +47,76 @@ namespace PlayerTests
TEST_CLASS(PlayerTest)
{
public:
std::unique_ptr<AiL>testGame;
InputGroup testKeyboardInput;
Player*player;
HWButton*testKey;
TEST_METHOD_INITIALIZE(PlayerInitialize){
testGame.reset(new AiL());
testGame->EnableTestingMode();
testGame->InitializeClasses();
testGame->InitializeDefaultKeybinds();
Tutorial::Initialize();
ItemAttribute::Initialize();
testGame->InitializePlayer();
Stats::InitializeDamageReductionTable();
player=testGame->GetPlayer();
//Setup key "0" as a test input
testKeyboardInput.AddKeybind(Input{InputType::KEY,0});
testKey=&testGame->pKeyboardState[0];
testGame->olc_UpdateKeyFocus(true); //Force the game to be "focused" for tests. Required if we want keyboard inputs to work.
}
TEST_METHOD(PlayerAlive){
Assert::IsTrue(player->IsAlive());
}
TEST_METHOD(PlayerTakesDamage){
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(70,player->GetHealth());
}
TEST_METHOD(PlayerBlockingTakesNoDamage){
player->SetState(State::BLOCK);
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(100,player->GetHealth());
}
TEST_METHOD(PlayerIframesPreventsDamage){
player->ApplyIframes(0.5f);
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(100,player->GetHealth());
}
TEST_METHOD(PlayerConsumesManaOnRightClickAbilityUse){
int abilityManaCost{player->GetRightClickAbility().manaCost};
testKey->bHeld=true; //Force the key to be held down for testing purposes.
player->CheckAndPerformAbility(player->GetRightClickAbility(),testKeyboardInput);
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
}
TEST_METHOD(PlayerConsumesManaOnAbility1Use){
int abilityManaCost{player->GetAbility1().manaCost};
testKey->bHeld=true; //Force the key to be held down for testing purposes.
player->CheckAndPerformAbility(player->GetAbility1(),testKeyboardInput);
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
}
TEST_METHOD(PlayerConsumesManaOnAbility2Use){
int abilityManaCost{player->GetAbility2().manaCost};
testKey->bHeld=true; //Force the key to be held down for testing purposes.
player->CheckAndPerformAbility(player->GetAbility2(),testKeyboardInput);
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
}
TEST_METHOD(PlayerConsumesManaOnAbility3Use){
int abilityManaCost{player->GetAbility3().manaCost};
testKey->bHeld=true; //Force the key to be held down for testing purposes.
player->CheckAndPerformAbility(player->GetAbility3(),testKeyboardInput);
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
}
TEST_METHOD(PlayerConsumesManaOnAbility4Use){
int abilityManaCost{player->GetAbility4().manaCost};
testKey->bHeld=true; //Force the key to be held down for testing purposes.
player->CheckAndPerformAbility(player->GetAbility4(),testKeyboardInput);
Assert::AreEqual(player->GetMaxMana()-abilityManaCost,player->GetMana());
}
TEST_METHOD(WarriorBlockActivatesBlock){
player->GetRightClickAbility().action(player,player->GetPos());
Assert::AreEqual(int(State::BLOCK),int(player->GetState()));
}
};
}