1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

tests: add ResistanceCondition test

This commit is contained in:
Konstantin P 2023-05-04 11:43:31 +03:00
parent 3d46ee3182
commit 75948a5dd7
3 changed files with 76 additions and 0 deletions

View File

@ -67,6 +67,7 @@ set(test_SRCS
spells/targetConditions/NormalLevelConditionTest.cpp
spells/targetConditions/NormalSpellConditionTest.cpp
spells/targetConditions/ReceptiveFeatureConditionTest.cpp
spells/targetConditions/ResistanceConditionTest.cpp
spells/targetConditions/SpellEffectConditionTest.cpp
spells/targetConditions/TargetConditionItemFixture.cpp

View File

@ -33,6 +33,9 @@ public:
MOCK_CONST_METHOD0(manaLimit, int32_t());
MOCK_CONST_METHOD0(getHeroCaster, CGHeroInstance*());
//ACreature
MOCK_CONST_METHOD0(magicResistance, int32_t());
MOCK_CONST_METHOD0(unitBaseAmount, int32_t());
MOCK_CONST_METHOD0(unitId, uint32_t());
MOCK_CONST_METHOD0(unitSide, ui8());

View File

@ -0,0 +1,72 @@
/*
* ElementalConditionTest.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "TargetConditionItemFixture.h"
namespace test
{
using namespace ::spells;
using namespace ::testing;
class ResistanceConditionTest : public TargetConditionItemTest, public WithParamInterface<bool>
{
public:
bool isPositive;
void setDefaultExpectations()
{
EXPECT_CALL(unitMock, getTreeVersion()).Times(AtLeast(0));
EXPECT_CALL(mechanicsMock, isPositiveSpell()).WillRepeatedly(Return(isPositive));
}
void SetUp() override
{
TargetConditionItemTest::SetUp();
subject = TargetConditionItemFactory::getDefault()->createResistance();
isPositive = GetParam();
}
};
TEST_P(ResistanceConditionTest, ReceptiveIfNoBonus)
{
setDefaultExpectations();
EXPECT_CALL(unitMock, magicResistance()).Times(AtLeast(0)).WillRepeatedly(Return(0));
EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
}
TEST_P(ResistanceConditionTest, DependsOnPositivness)
{
setDefaultExpectations();
EXPECT_CALL(unitMock, magicResistance()).Times(AtLeast(0)).WillRepeatedly(Return(100));
EXPECT_EQ(isPositive, subject->isReceptive(&mechanicsMock, &unitMock));
}
TEST_P(ResistanceConditionTest, ReceptiveIfResistanceIsLessThanHundred)
{
setDefaultExpectations();
EXPECT_CALL(unitMock, magicResistance()).Times(AtLeast(0)).WillRepeatedly(Return(99));
EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
}
INSTANTIATE_TEST_SUITE_P
(
ByPositiveness,
ResistanceConditionTest,
Values(false, true)
);
}