Fix bugs with static containers not being reset between unit test runs. Add in player test checks for seeded damage reduction test.

mac-build
sigonasr2 5 months ago
parent 0dc68d7f0c
commit 5193f382a3
  1. 18
      Adventures in Lestoria Tests/PlayerTests.cpp
  2. 5
      Adventures in Lestoria/Item.h
  3. 9
      Adventures in Lestoria/Menu.cpp
  4. 2
      Adventures in Lestoria/Version.h

@ -38,12 +38,15 @@ All rights reserved.
#include "CppUnitTest.h"
#include "AdventuresInLestoria.h"
#include "Tutorial.h"
#include <random>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace olc::utils;
INCLUDE_GFX
extern std::mt19937 rng;
namespace PlayerTests
{
TEST_CLASS(PlayerTest)
@ -54,6 +57,7 @@ namespace PlayerTests
Player*player;
HWButton*testKey;
TEST_METHOD_INITIALIZE(PlayerInitialize){
rng=std::mt19937{57189U};//Establish a fixed random seed on setup so the exact same results are generated every test run.
testGame.reset(new AiL());
testGame->olc_SetTestingMode(true);
ItemAttribute::Initialize();
@ -143,5 +147,19 @@ namespace PlayerTests
player->CheckAndPerformAbility(player->GetAbility2(),testKeyboardInput);
Assert::AreEqual(player->GetMaxMana(),player->GetMana());
}
TEST_METHOD(PlayerTakesDamageWithDamageReductionApplied){
std::weak_ptr<Item>testArmor{Inventory::AddItem("Bone Armor"s)};
testArmor.lock()->enhancementLevel="Item.Item Max Enhancement Level"_I; //Force enhance the item to the max enhancement level.
Inventory::EquipItem(testArmor,EquipSlot::ARMOR);
//If any of these values change, the armor piece may return a different value and these need to be updated for
//BONE ARMOR +10!
Assert::AreEqual(72.f,testArmor.lock()->GetStats().A_Read("Defense"));
Assert::AreEqual(14.f,testArmor.lock()->GetStats().A_Read("Health"));
Assert::AreEqual(7.f,testArmor.lock()->GetStats().A_Read("Attack"));
player->Hurt(30,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(74,player->GetHealth()); //Even though we are supposed to take 30 damage, damage reduction reduces it to 26 instead. (Random variance is controlled during testing. If this number changes at some point, either the damage formula or the item's stats have changed!)
}
};
}

@ -162,6 +162,10 @@ public:
const std::vector<std::pair<int,Stats>>&GetSetBonusBreakpoints()const;
};
namespace PlayerTests{
class PlayerTest;
};
class Item{
friend class Inventory;
friend class AiL;
@ -169,6 +173,7 @@ class Item{
friend class SaveFile;
friend void Merchant::PurchaseItem(IT item,uint32_t amt);
friend void Merchant::SellItem(std::weak_ptr<Item>,uint32_t amt);
friend class PlayerTests::PlayerTest;
private:
//The amount in the current item stack.
uint32_t amt;

@ -81,6 +81,15 @@ Menu::Menu(vf2d pos,vf2d size)
}
void Menu::InitializeMenus(){
std::for_each(menus.begin(),menus.end(),[](std::pair<MenuType,Menu*>data){delete data.second;}); //EW RAW POINTER.
menus.clear();
for(auto&[key,value]:DATA["ItemCategory"].GetKeys()){
inventoryListeners[key].clear();
merchantInventoryListeners[key].clear();
}
equipStatListeners.clear();
chapterListeners.clear();
stack.clear();
stack.reserve(MAX_MENUS);
InitializeConsumableInventoryWindow();
InitializeClassSelectionWindow();

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 2
#define VERSION_PATCH 3
#define VERSION_BUILD 9840
#define VERSION_BUILD 9849
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save