From e6a4e6d4dd0e85e02b1e8df2d1039404b6c7f4fb Mon Sep 17 00:00:00 2001 From: KylRikul <138259076+KylRikul@users.noreply.github.com> Date: Thu, 8 Oct 2026 12:16:28 +0200 Subject: [PATCH] Roll and cast each combat enchant effect only once - regression coverage --- tests/game/CombatEnchantProc.cpp | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/game/CombatEnchantProc.cpp diff --git a/tests/game/CombatEnchantProc.cpp b/tests/game/CombatEnchantProc.cpp new file mode 100644 index 0000000000..b755cddd19 --- /dev/null +++ b/tests/game/CombatEnchantProc.cpp @@ -0,0 +1,34 @@ +#include "tc_catch2.h" +#include "CombatEnchantProc.h" +#include + +TEST_CASE("A successful enchant effect rolls and casts once", "[CombatEnchantProc]") +{ + std::vector chances; + unsigned casts = 0; + CombatEnchantProc::Dispatch(37.5f, [&](float chance) { chances.push_back(chance); return true; }, [&] { ++casts; }); + REQUIRE(chances.size() == 1); + CHECK(chances.front() == 37.5f); + CHECK(casts == 1); +} + +TEST_CASE("A missed enchant effect has no second attempt", "[CombatEnchantProc]") +{ + unsigned rolls = 0, casts = 0; + CombatEnchantProc::Dispatch(12.5f, [&](float chance) { CHECK(chance == 12.5f); return rolls++ != 0; }, [&] { ++casts; }); + CHECK(rolls == 1); + CHECK(casts == 0); +} + +TEST_CASE("Separate enchant effects retain separate chances and item cast callbacks", "[CombatEnchantProc]") +{ + unsigned rolls = 0; + std::vector spells; + auto roll = [&](float chance) { CHECK(chance == 17.25f); return ++rolls != 2; }; + for (unsigned spell : { 8034u, 8037u, 10458u }) + CombatEnchantProc::Dispatch(17.25f, roll, [&] { spells.push_back(spell); }); + CHECK(rolls == 3); + REQUIRE(spells.size() == 2); + CHECK(spells[0] == 8034); + CHECK(spells[1] == 10458); +}