archer_bonus_test.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "core/component.h"
  2. #include "core/entity.h"
  3. #include "core/world.h"
  4. #include "systems/combat_system/combat_types.h"
  5. #include "systems/owner_registry.h"
  6. #include "units/spawn_type.h"
  7. #include <gtest/gtest.h>
  8. using namespace Engine::Core;
  9. using namespace Game::Systems;
  10. class ArcherBonusTest : public ::testing::Test {
  11. protected:
  12. void SetUp() override {
  13. world = std::make_unique<World>();
  14. OwnerRegistry::instance().clear();
  15. }
  16. void TearDown() override { world.reset(); }
  17. std::unique_ptr<World> world;
  18. };
  19. TEST_F(ArcherBonusTest, ArcherHasIncreasedBaseDamage) {
  20. // Verify that archer base damage has been increased from 16 to 24 (1.5x)
  21. // This test documents the expected base damage value
  22. int const expected_archer_damage = 24;
  23. int const original_archer_damage = 16;
  24. EXPECT_EQ(expected_archer_damage, original_archer_damage * 1.5);
  25. }
  26. TEST_F(ArcherBonusTest, HorseArcherHasIncreasedBaseDamage) {
  27. // Verify that horse archer base damage has been increased from 18 to 27
  28. // (1.5x) This test documents the expected base damage value
  29. int const expected_horse_archer_damage = 27;
  30. int const original_horse_archer_damage = 18;
  31. EXPECT_EQ(expected_horse_archer_damage, original_horse_archer_damage * 1.5);
  32. }
  33. TEST_F(ArcherBonusTest, ArcherVsElephantMultiplierIsCorrect) {
  34. // Verify the archer vs elephant multiplier constant is set correctly
  35. float const expected_multiplier = 2.0F;
  36. EXPECT_FLOAT_EQ(Combat::Constants::k_archer_vs_elephant_multiplier,
  37. expected_multiplier);
  38. }
  39. TEST_F(ArcherBonusTest, ElephantComponentExistsOnElephantUnit) {
  40. // Create an elephant unit and verify it has the ElephantComponent
  41. auto *elephant = world->create_entity();
  42. elephant->add_component<TransformComponent>(0.0F, 0.0F, 0.0F);
  43. auto *elephant_unit =
  44. elephant->add_component<UnitComponent>(8000, 8000, 2.2F, 16.0F);
  45. elephant_unit->spawn_type = Game::Units::SpawnType::Elephant;
  46. elephant->add_component<ElephantComponent>();
  47. EXPECT_TRUE(elephant->has_component<ElephantComponent>());
  48. }
  49. TEST_F(ArcherBonusTest, NonElephantUnitsDoNotHaveElephantComponent) {
  50. // Verify that non-elephant units don't have ElephantComponent
  51. auto *spearman = world->create_entity();
  52. spearman->add_component<TransformComponent>(0.0F, 0.0F, 0.0F);
  53. auto *spearman_unit =
  54. spearman->add_component<UnitComponent>(1260, 1260, 2.1F, 14.0F);
  55. spearman_unit->spawn_type = Game::Units::SpawnType::Spearman;
  56. EXPECT_FALSE(spearman->has_component<ElephantComponent>());
  57. }
  58. TEST_F(ArcherBonusTest, ExpectedDamageCalculation) {
  59. // Document the expected damage calculations:
  60. // Archer vs Elephant: 24 (base) * 2.0 (multiplier) = 48
  61. // Horse Archer vs Elephant: 27 (base) * 2.0 (multiplier) = 54
  62. // Archer vs Other: 24 (base) * 1.0 (no multiplier) = 24
  63. int const archer_base_damage = 24;
  64. int const horse_archer_base_damage = 27;
  65. float const elephant_multiplier =
  66. Combat::Constants::k_archer_vs_elephant_multiplier;
  67. int const archer_vs_elephant =
  68. static_cast<int>(archer_base_damage * elephant_multiplier);
  69. int const horse_archer_vs_elephant =
  70. static_cast<int>(horse_archer_base_damage * elephant_multiplier);
  71. int const archer_vs_other = archer_base_damage;
  72. EXPECT_EQ(archer_vs_elephant, 48);
  73. EXPECT_EQ(horse_archer_vs_elephant, 54);
  74. EXPECT_EQ(archer_vs_other, 24);
  75. }