Add Player HP Recovery tests. 90/90 tests passing.

removeExposedPackKey
sigonasr2 5 months ago
parent 3e8c7ddfc0
commit 29f97a901a
  1. 51
      Adventures in Lestoria Tests/PlayerTests.cpp

@ -517,5 +517,56 @@ namespace PlayerTests
Assert::AreEqual(100,player->GetMana(),L"Mana is still 100");
Assert::AreEqual(200,player->GetMaxMana(),L"Max Mana is now 200");
}
TEST_METHOD(HP6RecoveryTest){
std::weak_ptr<Item>setArmor{Inventory::AddItem("Test Armor2"s)};
game->SetElapsedTime(0.1f);
game->OnUserUpdate(0.1f); //Advance the game by 0.1s so that all healing ticks occur at least once.
//Hurt the player for most of their health.
player->Hurt(player->GetMaxHealth()-1,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(1,player->GetHealth(),L"Player is at 1 Health.");
Inventory::EquipItem(setArmor,EquipSlot::ARMOR);
Assert::AreEqual(100.0_Pct,player->GetHP6RecoveryPct(),L"HP6 Recovery % is 100%");
game->SetElapsedTime(3.f);
game->OnUserUpdate(3.f); //Wait 3 seconds. The player shouldn't be healed yet.
Assert::AreEqual(1,player->GetHealth(),L"After waiting for 3 seconds, the player should still be at 1 health.");
game->SetElapsedTime(3.f);
game->OnUserUpdate(3.f); //Wait 3 more seconds. The player should be healed now.
Assert::AreEqual(player->GetMaxHealth(),player->GetHealth(),L"After waiting for 6 seconds, the player should be at full health.");
}
TEST_METHOD(HP4RecoveryTest){
std::weak_ptr<Item>setArmor{Inventory::AddItem("Test Armor3"s)};
game->SetElapsedTime(0.1f);
game->OnUserUpdate(0.1f); //Advance the game by 0.1s so that all healing ticks occur at least once.
//Hurt the player for most of their health.
player->Hurt(player->GetMaxHealth()-1,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(1,player->GetHealth(),L"Player is at 1 Health.");
Inventory::EquipItem(setArmor,EquipSlot::ARMOR);
Assert::AreEqual(100.0_Pct,player->GetHP4RecoveryPct(),L"HP4 Recovery % is 100%");
game->SetElapsedTime(2.f);
game->OnUserUpdate(2.f); //Wait 2 seconds. The player shouldn't be healed yet.
Assert::AreEqual(1,player->GetHealth(),L"After waiting for 2 seconds, the player should still be at 1 health.");
game->SetElapsedTime(2.f);
game->OnUserUpdate(2.f); //Wait 2 more seconds. The player should be healed now.
Assert::AreEqual(player->GetMaxHealth(),player->GetHealth(),L"After waiting for 4 seconds, the player should be at full health.");
}
TEST_METHOD(HPRecoveryTest){
std::weak_ptr<Item>setArmor{Inventory::AddItem("Test Armor4"s)};
game->SetElapsedTime(0.1f);
game->OnUserUpdate(0.1f); //Advance the game by 0.1s so that all healing ticks occur at least once.
//Hurt the player for most of their health.
player->Hurt(player->GetMaxHealth()-1,player->OnUpperLevel(),player->GetZ());
Assert::AreEqual(1,player->GetHealth(),L"Player is at 1 Health.");
Inventory::EquipItem(setArmor,EquipSlot::ARMOR);
Assert::AreEqual(100.0_Pct,player->GetHPRecoveryPct(),L"HP Recovery % is 100%");
game->SetElapsedTime(0.5f);
game->OnUserUpdate(0.5f); //Wait 0.5 seconds. The player shouldn't be healed yet.
Assert::AreEqual(1,player->GetHealth(),L"After waiting for 0.5 seconds, the player should still be at 1 health.");
game->SetElapsedTime(0.5f);
game->OnUserUpdate(0.5f); //Wait 0.5 more seconds. The player should be healed now.
Assert::AreEqual(player->GetMaxHealth(),player->GetHealth(),L"After waiting for 1 second, the player should be at full health.");
}
};
}

Loading…
Cancel
Save