@ -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!)
}
} ;
}