Added stat-based item enchant checks. Remove friend class dependencies from unit tests and added appropriate publicly exposed functions. Release Build 10538.
parent
d4d325503e
commit
2f244e21ff
@ -0,0 +1,213 @@ |
|||||||
|
#pragma region License |
||||||
|
/*
|
||||||
|
License (OLC-3) |
||||||
|
~~~~~~~~~~~~~~~ |
||||||
|
|
||||||
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com> |
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, |
||||||
|
are permitted provided that the following conditions are met: |
||||||
|
|
||||||
|
1. Redistributions or derivations of source code must retain the above copyright |
||||||
|
notice, this list of conditions and the following disclaimer. |
||||||
|
|
||||||
|
2. Redistributions or derivative works in binary form must reproduce the above |
||||||
|
copyright notice. This list of conditions and the following disclaimer must be |
||||||
|
reproduced in the documentation and/or other materials provided with the distribution. |
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its contributors may |
||||||
|
be used to endorse or promote products derived from this software without specific |
||||||
|
prior written permission. |
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
||||||
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
||||||
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
||||||
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||||
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||||||
|
SUCH DAMAGE. |
||||||
|
|
||||||
|
Portions of this software are copyright © 2024 The FreeType |
||||||
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information. |
||||||
|
All rights reserved. |
||||||
|
*/ |
||||||
|
#pragma endregion |
||||||
|
#include "CppUnitTest.h" |
||||||
|
#include "AdventuresInLestoria.h" |
||||||
|
#include "Tutorial.h" |
||||||
|
#include <random> |
||||||
|
#include <format> |
||||||
|
#include "ItemDrop.h" |
||||||
|
#include "DamageNumber.h" |
||||||
|
#include <ranges> |
||||||
|
|
||||||
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework; |
||||||
|
using namespace olc::utils; |
||||||
|
|
||||||
|
INCLUDE_GFX |
||||||
|
INCLUDE_ITEM_DATA |
||||||
|
INCLUDE_DAMAGENUMBER_LIST |
||||||
|
|
||||||
|
extern std::mt19937 rng; |
||||||
|
|
||||||
|
namespace Test |
||||||
|
{ |
||||||
|
template<class T> |
||||||
|
inline static void InRange(T initialVal,std::pair<T,T>range,std::wstring_view assertMessage){ |
||||||
|
Assert::IsTrue(initialVal>=range.first&&initialVal<=range.second,std::format(L"Expected: {}~{} Actual: {} - {}",range.first,range.second,initialVal,assertMessage).c_str()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
namespace EnchantTests |
||||||
|
{ |
||||||
|
TEST_CLASS(EnchantTest) |
||||||
|
{ |
||||||
|
public: |
||||||
|
std::unique_ptr<AiL>testGame; |
||||||
|
InputGroup testKeyboardInput; |
||||||
|
Player*player; |
||||||
|
const 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(true)); |
||||||
|
ItemAttribute::Initialize(); |
||||||
|
ItemInfo::InitializeItems(); |
||||||
|
testGame->InitializeGraphics(); |
||||||
|
testGame->InitializeClasses(); |
||||||
|
sig::Animation::InitializeAnimations(); |
||||||
|
testGame->InitializeDefaultKeybinds(); |
||||||
|
testGame->InitializePlayer(); |
||||||
|
sig::Animation::SetupPlayerAnimations(); |
||||||
|
Menu::InitializeMenus(); |
||||||
|
Tutorial::Initialize(); |
||||||
|
Stats::InitializeDamageReductionTable(); |
||||||
|
|
||||||
|
GameState::Initialize(); |
||||||
|
GameState::STATE=GameState::states.at(States::State::GAME_RUN); |
||||||
|
|
||||||
|
#pragma region Setup a fake test map and test monster |
||||||
|
game->MAP_DATA["CAMPAIGN_1_1"]; |
||||||
|
ItemDrop::ClearDrops(); |
||||||
|
MonsterData testMonsterData{"TestName","Test Monster",1000,10,5,{MonsterDropData{"Health Potion",100.f,1,1}},200.f}; |
||||||
|
MONSTER_DATA["TestName"]=testMonsterData; |
||||||
|
#pragma endregion |
||||||
|
|
||||||
|
player=testGame->GetPlayer(); |
||||||
|
//Setup key "0" as a test input
|
||||||
|
testKeyboardInput.AddKeybind(Input{InputType::KEY,0}); |
||||||
|
testKey=testGame->GetKeyboardState(0); |
||||||
|
testGame->olc_UpdateKeyFocus(true); //Force the game to be "focused" for tests. Required if we want keyboard inputs to work.
|
||||||
|
Menu::themes.SetInitialized(); |
||||||
|
GFX.SetInitialized(); |
||||||
|
|
||||||
|
DAMAGENUMBER_LIST.clear(); |
||||||
|
} |
||||||
|
TEST_METHOD(HealthBoostCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(100,player->GetMaxHealth(),L"Player starts with 100 health."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Health Boost"); |
||||||
|
Test::InRange(player->GetMaxHealth(),{103,105},L"Max Health not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(AttackBoostCheck){ |
||||||
|
player->SetBaseStat("Attack",100.f); |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(100,player->GetAttack(),L"Player starts with 100 attack."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Attack Boost"); |
||||||
|
Test::InRange(player->GetAttack(),{103,105},L"Attack not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(MovementBoostCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(100.0_Pct,player->GetMoveSpdMult(),L"Player starts with 100% Movespd."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Movement Boost"); |
||||||
|
Test::InRange(player->GetMoveSpdMult(),{103.0_Pct,105.0_Pct},L"Move Speed not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(AbilityHasteCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetCooldownReductionPct(),L"Player starts with 0% CDR."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Ability Haste"); |
||||||
|
Test::InRange(player->GetCooldownReductionPct(),{3.0_Pct,5.0_Pct},L"CDR not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(CritRateCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetCritRatePct(),L"Player starts with 0% Crit Rate."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Crit Rate"); |
||||||
|
Test::InRange(player->GetCritRatePct(),{3.0_Pct,5.0_Pct},L"Crit Rate not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(CritDamageCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(50.0_Pct,player->GetCritDmgPct(),L"Player starts with 50% Crit Damage."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Crit Damage"); |
||||||
|
Test::InRange(player->GetCritDmgPct(),{57.0_Pct,60.0_Pct},L"Crit Damage not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(StoneskinCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetDamageReductionPct(),L"Player starts with 0% Damage Reduction."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Stoneskin"); |
||||||
|
Test::InRange(player->GetDamageReductionPct(),{3.0_Pct,5.0_Pct},L"Damage Reduction not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(ManaPoolCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(100,player->GetMaxMana(),L"Player starts with 100 mana."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Mana Pool"); |
||||||
|
Test::InRange(player->GetMaxMana(),{107,112},L"Mana Pool not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(MagicalProtectionCheck){ |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(100,player->GetMaxHealth(),L"Player starts with 100 health."); |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetDamageReductionPct(),L"Player starts with 0% damage reduction."); |
||||||
|
Assert::AreEqual(100.0_Pct,player->GetMoveSpdMult(),L"Player starts with 100% move speed."); |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetHP6RecoveryPct(),L"Player starts with 0% HP/6 recovery."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Magical Protection"); |
||||||
|
Test::InRange(player->GetMaxHealth(),{102,103},L"Max Health not in expected range."); |
||||||
|
Test::InRange(player->GetDamageReductionPct(),{2.0_Pct,3.0_Pct},L"Damage Reduction not in expected range."); |
||||||
|
Test::InRange(player->GetMoveSpdMult(),{102.0_Pct,103.0_Pct},L"Move Speed % not in expected range."); |
||||||
|
Test::InRange(player->GetHP6RecoveryPct(),{1.0_Pct,1.0_Pct},L"HP/6 Recovery not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
TEST_METHOD(AuraOfTheBeastCheck){ |
||||||
|
player->SetBaseStat("Attack",100.f); |
||||||
|
std::weak_ptr<Item>nullRing{Inventory::AddItem("Null Ring"s)}; |
||||||
|
Assert::AreEqual(100,player->GetAttack(),L"Player starts with 100 attack."); |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetCritRatePct(),L"Player starts with 0% crit rate."); |
||||||
|
Assert::AreEqual(0.0_Pct,player->GetCooldownReductionPct(),L"Player starts with 0% cooldown reduction."); |
||||||
|
Assert::AreEqual(50.0_Pct,player->GetCritDmgPct(),L"Player starts with 50% crit rate."); |
||||||
|
Inventory::EquipItem(nullRing,EquipSlot::RING1); |
||||||
|
for(int i:std::ranges::iota_view(0,1000)){ |
||||||
|
nullRing.lock()->EnchantItem("Aura of the Beast"); |
||||||
|
Test::InRange(player->GetAttack(),{102,103},L"Attack not in expected range."); |
||||||
|
Test::InRange(player->GetCritRatePct(),{2.0_Pct,3.0_Pct},L"Crit Rate not in expected range."); |
||||||
|
Test::InRange(player->GetCooldownReductionPct(),{2.0_Pct,3.0_Pct},L"Cooldown Reduction % not in expected range."); |
||||||
|
Test::InRange(player->GetCritDmgPct(),{53.0_Pct,57.0_Pct},L"Crit Damage not in expected range."); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
Binary file not shown.
Loading…
Reference in new issue