From 5193f382a3620e9989f27ff78dfedafead4a099b Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 25 Jun 2024 16:51:52 -0500 Subject: [PATCH] Fix bugs with static containers not being reset between unit test runs. Add in player test checks for seeded damage reduction test. --- Adventures in Lestoria Tests/PlayerTests.cpp | 18 ++++++++++++++++++ Adventures in Lestoria/Item.h | 5 +++++ Adventures in Lestoria/Menu.cpp | 9 +++++++++ Adventures in Lestoria/Version.h | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Adventures in Lestoria Tests/PlayerTests.cpp b/Adventures in Lestoria Tests/PlayerTests.cpp index d6c1bacb..d38abec5 100644 --- a/Adventures in Lestoria Tests/PlayerTests.cpp +++ b/Adventures in Lestoria Tests/PlayerTests.cpp @@ -38,12 +38,15 @@ All rights reserved. #include "CppUnitTest.h" #include "AdventuresInLestoria.h" #include "Tutorial.h" +#include 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_ptrtestArmor{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!) + } }; } diff --git a/Adventures in Lestoria/Item.h b/Adventures in Lestoria/Item.h index ffeb2a41..32ef202c 100644 --- a/Adventures in Lestoria/Item.h +++ b/Adventures in Lestoria/Item.h @@ -162,6 +162,10 @@ public: const std::vector>&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,uint32_t amt); + friend class PlayerTests::PlayerTest; private: //The amount in the current item stack. uint32_t amt; diff --git a/Adventures in Lestoria/Menu.cpp b/Adventures in Lestoria/Menu.cpp index 86150b13..658042db 100644 --- a/Adventures in Lestoria/Menu.cpp +++ b/Adventures in Lestoria/Menu.cpp @@ -81,6 +81,15 @@ Menu::Menu(vf2d pos,vf2d size) } void Menu::InitializeMenus(){ + std::for_each(menus.begin(),menus.end(),[](std::pairdata){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(); diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 5016c2f6..e67c1b37 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -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