Item Loadout Usage Tests added. 101/101 unit tests passing. Release Build 9947.

This commit is contained in:
2024-07-09 10:49:12 -05:00
parent 01d61c95f4
commit 9d95796062
5 changed files with 59 additions and 1 deletions
@@ -123,5 +123,60 @@ namespace ItemTests
Assert::IsFalse(game->UseLoadoutItem(1),L"Using a blank loadout item slot (1) does not produce a result.");
Assert::IsFalse(game->UseLoadoutItem(2),L"Using a blank loadout item slot (2) does not produce a result.");
}
TEST_METHOD(UsingLoadoutItemOfQuantityZeroDoesNothing){
Assert::ExpectException<std::exception>([](){game->SetLoadoutItem(0,"Minor Health Potion");},L"Applying an item that doesn't exist to a loadout slot should not be allowed.");
}
TEST_METHOD(UsingLoadoutItemConsumesIt){
player->Hurt(1,player->OnUpperLevel(),player->GetZ());
Inventory::AddItem("Minor Health Potion"s,5U);
game->SetLoadoutItem(0,"Minor Health Potion");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem1,testKeyboardInput);
Assert::AreEqual(1,Inventory::loadoutItemsUsed[0].second,L"1 Health potion considered used in loadout inventory.");
Assert::AreEqual(4U,Inventory::GetItemCount("Minor Health Potion"s),L"4 Health potions remain in player's inventory.");
Assert::AreEqual(player->useItem1.GetCooldownTime(),player->useItem1.cooldown,L"Item 1 is now on cooldown.");
}
TEST_METHOD(ItemScriptBuffTest){
player->Hurt(1,player->OnUpperLevel(),player->GetZ());
Inventory::AddItem("Stat Up Everything Potion"s,5U);
game->SetLoadoutItem(0,"Stat Up Everything Potion");
testKey->bHeld=true; //Simulate key being pressed.
Assert::ExpectException<std::exception>([&](){player->CheckAndPerformAbility(player->useItem1,testKeyboardInput);},L"If all buffs are properly applied, then some of these stat up buffs are illegal and will catch an exception.");
}
TEST_METHOD(FlatRestoreScriptTest){
player->Hurt(75,player->OnUpperLevel(),player->GetZ());
player->mana=25;
Inventory::AddItem("Flat Recovery Potion"s,5U);
game->SetLoadoutItem(0,"Flat Recovery Potion");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem1,testKeyboardInput);
Assert::AreEqual(75,player->GetHealth(),L"Player Health is 75 after using Flat Recovery Potion.");
Assert::AreEqual(75,player->GetMana(),L"Player Mana is 75 after using Flat Recovery Potion.");
}
TEST_METHOD(PctRestoreScriptTest){
player->Hurt(75,player->OnUpperLevel(),player->GetZ());
player->mana=25;
Inventory::AddItem("Pct Recovery Potion"s,5U);
game->SetLoadoutItem(1,"Pct Recovery Potion");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem2,testKeyboardInput);
Assert::AreEqual(75,player->GetHealth(),L"Player Health is 75 after using Pct Recovery Potion.");
Assert::AreEqual(75,player->GetMana(),L"Player Mana is 75 after using Pct Recovery Potion.");
}
TEST_METHOD(HealOverTimeTest){
player->Hurt(75,player->OnUpperLevel(),player->GetZ());
Inventory::AddItem("Bandages"s,5U);
game->SetLoadoutItem(2,"Bandages");
testKey->bHeld=true; //Simulate key being pressed.
player->CheckAndPerformAbility(player->useItem3,testKeyboardInput);
Assert::AreEqual(30,player->GetHealth(),L"Player is immediately healed for 5 health points on Bandages use.");
game->SetElapsedTime(1.f);
game->OnUserUpdate(1.f);
for(int seconds{1};seconds<=6;seconds++){
Assert::AreEqual(30+seconds*5,player->GetHealth(),L"Player is healed again for 5 health points.");
game->OnUserUpdate(1.f);
}
Assert::AreEqual(60,player->GetHealth(),L"Player should not be healed now that the Bandages effect is over.");
}
};
}