The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'! https://forums.lestoria.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
AdventuresInLestoria/Adventures in Lestoria Tests/Adventures in Lestoria Test...

161 lines
5.9 KiB

#include "CppUnitTest.h"
#include "olcUTIL_Geometry2D.h"
#include "AdventuresInLestoria.h"
#include "config.h"
#include "ItemDrop.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace olc::utils;
INCLUDE_MONSTER_DATA
INCLUDE_game
TEST_MODULE_INITIALIZE(AiLTestSuite)
{
debugLogger.open("debug.log");
}
namespace MonsterTests
{
TEST_CLASS(MonsterTest)
{
public:
std::unique_ptr<AiL>testGame;
#pragma region Setup Functions
//Makes MONSTER_DATA["TestName"] available.
void SetupTestMonster(){
testGame.reset(new AiL());
testGame->EnableTestingMode();
ItemAttribute::Initialize();
ItemInfo::InitializeItems();
testGame->InitializePlayer();
Stats::InitializeDamageReductionTable();
MonsterData testMonsterData{"TestName","Test Monster",30,10,5,{MonsterDropData{"Health Potion",100.f,1,1}},200.f};
MONSTER_DATA["TestName"]=testMonsterData;
}
void SetupMockMap(){
game->MAP_DATA["CAMPAIGN_1_1"];
}
#pragma endregion
TEST_METHOD_INITIALIZE(MonsterInitialize){
SetupTestMonster();
SetupMockMap();
}
~MonsterTest(){
testGame.release();
}
TEST_METHOD(DisplayNameCheck){
Assert::AreEqual("Test Monster",MONSTER_DATA["TestName"].GetDisplayName().c_str());
}
TEST_METHOD(InternalNameCheck){
Monster testMonster{{},MONSTER_DATA["TestName"]};
Assert::AreEqual("TestName",testMonster.GetName().c_str());
}
TEST_METHOD(HealthCheck){
Monster testMonster{{},MONSTER_DATA["TestName"]};
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth());
Assert::AreEqual(testMonster.GetHealth(),30);
}
TEST_METHOD(Deal5Damage)
{
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.Hurt(5,testMonster.OnUpperLevel(),testMonster.GetZ());
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth()-5);
}
TEST_METHOD(IFrameShouldResultInNoDamage){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.ApplyIframes(0.5f);
testMonster.Hurt(5,testMonster.OnUpperLevel(),testMonster.GetZ());
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth());
}
TEST_METHOD(BeingInTheAirShouldAvoidAttacksFromTheGround){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.SetZ(2.f);
testMonster.Hurt(5,testMonster.OnUpperLevel(),0.f);
Assert::AreEqual(testMonster.GetHealth(),testMonster.GetMaxHealth());
}
TEST_METHOD(MonstersDeal10Damage_NoDamageReduction)
{
Monster testMonster{{},MONSTER_DATA["TestName"]};
Monster testMonster2{{},MONSTER_DATA["TestName"]};
game->GetPlayer()->Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
testMonster2.Hurt(testMonster.GetAttack(),testMonster.OnUpperLevel(),testMonster.GetZ());
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-10,game->GetPlayer()->GetHealth());
Assert::AreEqual(testMonster2.GetMaxHealth()-10,testMonster2.GetHealth());
}
TEST_METHOD(DoubleAttackPctModifierWorks){
Monster buffMonster{{},MONSTER_DATA["TestName"]};
buffMonster.AddBuff(BuffType::STAT_UP,5,100._Pct,{ItemAttribute::Get("Attack %")});
Monster testMonster2{{},MONSTER_DATA["TestName"]};
game->GetPlayer()->Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
testMonster2.Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-20,game->GetPlayer()->GetHealth());
Assert::AreEqual(testMonster2.GetMaxHealth()-20,testMonster2.GetHealth());
}
TEST_METHOD(AttackUpModifierWorks){
Monster buffMonster{{},MONSTER_DATA["TestName"]};
buffMonster.AddBuff(BuffType::STAT_UP,5,5.f,{ItemAttribute::Get("Attack")});
Monster testMonster2{{},MONSTER_DATA["TestName"]};
game->GetPlayer()->Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
testMonster2.Hurt(buffMonster.GetAttack(),buffMonster.OnUpperLevel(),buffMonster.GetZ());
Assert::AreEqual(game->GetPlayer()->GetMaxHealth()-15,game->GetPlayer()->GetHealth());
Assert::AreEqual(testMonster2.GetMaxHealth()-15,testMonster2.GetHealth());
}
TEST_METHOD(MonsterIsConsideredDeadAt0Health){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.Hurt(testMonster.GetMaxHealth(),testMonster.OnUpperLevel(),testMonster.GetZ());
Assert::AreEqual(true,testMonster.IsDead());
}
TEST_METHOD(ItemDropSpawnsWhenMonsterIsKilled){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.Hurt(testMonster.GetMaxHealth(),testMonster.OnUpperLevel(),testMonster.GetZ());
Assert::AreEqual(size_t(1),ItemDrop::GetDrops().size());
}
TEST_METHOD(MoveSpdSetCorrectly){
Monster testMonster{{},MONSTER_DATA["TestName"]};
Assert::AreEqual(2.f,testMonster.GetMoveSpdMult());
}
TEST_METHOD(SlowdownBuffTest){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.AddBuff(BuffType::SLOWDOWN,5.f,0.5f);
Assert::AreEqual(1.f,testMonster.GetMoveSpdMult());
}
TEST_METHOD(SelfInflictedSlowdownTest){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.AddBuff(BuffType::SELF_INFLICTED_SLOWDOWN,5.f,0.5f);
Assert::AreEqual(1.f,testMonster.GetMoveSpdMult());
}
TEST_METHOD(SpeedBoostTest){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.AddBuff(BuffType::SPEEDBOOST,5.f,0.5f);
Assert::AreEqual(3.f,testMonster.GetMoveSpdMult());
}
TEST_METHOD(LockOnSpeedBoostTest){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.AddBuff(BuffType::LOCKON_SPEEDBOOST,5.f,0.5f);
Assert::AreEqual(3.f,testMonster.GetMoveSpdMult());
}
TEST_METHOD(AdditiveMoveSpdBuffsTest){
Monster testMonster{{},MONSTER_DATA["TestName"]};
testMonster.AddBuff(BuffType::SLOWDOWN,5.f,0.5f);
testMonster.AddBuff(BuffType::SPEEDBOOST,5.f,0.75f);
Assert::AreEqual(2.5f,testMonster.GetMoveSpdMult());
}
};
}
namespace GeometryTests
{
TEST_CLASS(GeometryTest)
{
public:
TEST_METHOD(CircleOverlapTest)
{
Assert::IsTrue(geom2d::overlaps(geom2d::circle<float>{vf2d{},10},vf2d{5,5}));
}
};
}