JD2022-TU1/main/unittests/JD/gameplay/Managers/JD_MoveInterface.cpp

124 lines
5.8 KiB
C++

// ----------------------------------------------------------------------------
// Unit test for the class JD_MoveInterface
// ----------------------------------------------------------------------------
#include "JD_precompiled_unittests_gameplay.h"
#if defined( ITF_USE_MOVESPACEGESTURE )
#include "JD_MoveInterface_Testable.h"
#include "JD_GameManager_Mock.h"
#include "JD_GameContextManager_Mock.h"
#include "engine/GoTop/ProtectionManager.h"
#include "../Tapes/broadcaster/TapeEventBroadcaster_Mock.h"
namespace ITF
{
using namespace testing;
TEST(JD_MoveInterface, test_computeAndGetMovespaceFinalScore)
{
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// setup/arrange
// -----------------------------------------------------------------------------------------------------------------------------------------------------
ProtectionManager protectionMgr;
CREATE_CLASS_SINGLETON(XMLConfig);
CREATE_CLASS_SINGLETON(NiceMock<TapeEventBroadcaster_Mock>);
CREATE_CLASS_SINGLETON(NiceMock<JD_GameManager_Mock>);
CREATE_CLASS_SINGLETON(NiceMock<JD_GameContextManager_Mock>);
ON_CALL(*((JD_GameManager_Mock*)JD_GAMEMANAGER), getScoringMode()).WillByDefault(Return(eScoringMode_HandController));
ON_CALL(*((JD_GameContextManager_Mock*)JD_GAMECONTEXT_MANAGER), isCurrentContext(StringID(s_contextKids))).WillByDefault(Return(bfalse));
JD_MoveInterface_Testable* moveInterface = new JD_MoveInterface_Testable(); // pointer used instead of instance because moveInterface destruction uses a mocked singleton (TapeEventBroadcaster_Mock)
ScoringMovespaceParams scoringMovespaceParams;
scoringMovespaceParams.m_phoneShakeDetectedMaxScoreRatio = 0.1f;
scoringMovespaceParams.m_phoneDirectionMalusMultiplier = 1.0f;
scoringMovespaceParams.m_charityEnergyFactorFloor = 0.6f;
scoringMovespaceParams.m_perfectMalusEnergyFactorCeil = 0.4f;
scoringMovespaceParams.m_switchJoyConDirectionMalusMultiplier = 1.0f;
moveInterface->setScoringParams(scoringMovespaceParams);
#if defined (ITF_USE_MOVESPACEGESTURE)
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// act/assert
// -----------------------------------------------------------------------------------------------------------------------------------------------------
f32 score;
// score under OK (0.25) not saved by charity
score = moveInterface->computeAndGetMovespaceFinalScore(
/*mspScore*/ 0.24f, /*enrgAmount*/ 10.0f, /*enrgFactor*/ 0.1f, /*ACTime*/ - 5.0f, /*dirTendIgnore*/ true, /*dirTendImpactOnScoreRatio*/ 0.5f, /*songScoreRatio*/ 0.0f);
EXPECT_EQ(0.0f, score);
// score under OK (0.25) saved by charity
score = moveInterface->computeAndGetMovespaceFinalScore(
/*mspScore*/ 0.1f, /*enrgAmount*/ 5.0f, /*enrgFactor*/ 0.9f, /*ACTime*/ 0.25f, /*dirTendIgnore*/ false, /*dirTendImpactOnScoreRatio*/ - 0.2f, /*songScoreRatio*/ 0.0f);
EXPECT_EQ(0.1f, score);
// no-move penalty
score = moveInterface->computeAndGetMovespaceFinalScore(
/*mspScore*/ 0.9f, /*enrgAmount*/ 0.1f, /*enrgFactor*/ 0.8f, /*ACTime*/ - 2.0f, /*dirTendIgnore*/ false, /*dirTendImpactOnScoreRatio*/ 0.1f, /*songScoreRatio*/ 0.0f);
EXPECT_EQ(0.0f, score);
// shake penalty, saved by charity
score = moveInterface->computeAndGetMovespaceFinalScore(
/*mspScore*/ 0.7f, /*enrgAmount*/ 3.0f, /*enrgFactor*/ 1.0f, /*ACTime*/ 0.25f, /*dirTendIgnore*/ true, /*dirTendImpactOnScoreRatio*/ 0.3f, /*songScoreRatio*/ 0.0f);
EXPECT_EQ(0.1f, score);
// direction bonus
score = moveInterface->computeAndGetMovespaceFinalScore(
/*mspScore*/ 0.5f, /*enrgAmount*/ 8.0f, /*enrgFactor*/ 1.0f, /*ACTime*/ - 1.0f, /*dirTendIgnore*/ false, /*dirTendImpactOnScoreRatio*/ 0.9f, /*songScoreRatio*/ 0.0f);
EXPECT_NEAR(0.59f, score, 0.0001f);
// direction malus
score = moveInterface->computeAndGetMovespaceFinalScore(
/*mspScore*/ 1.0f, /*enrgAmount*/ 2.0f, /*enrgFactor*/ 1.3f, /*ACTime*/ - 1.0f, /*dirTendIgnore*/ false, /*dirTendImpactOnScoreRatio*/ - 0.6f, /*songScoreRatio*/ 0.0f);
EXPECT_NEAR(0.4f, score, 0.0001f);
// // direction bonus + perfect malus
//
// score = moveInterface->computeAndGetMovespaceFinalScore(
// /*mspScore*/ 0.7f, /*enrgAmount*/ 6.0f, /*enrgFactor*/ 0.2f, /*ACTime*/ - 1.0f, /*dirTendIgnore*/ false, /*dirTendImpactOnScoreRatio*/ 0.9f, /*songScoreRatio*/ 0.0f);
//
// EXPECT_EQ(0.74f, score);
//
// // direction malus + score under OK not saved by charity
//
// score = moveInterface->computeAndGetMovespaceFinalScore(
// /*mspScore*/ 0.9f, /*enrgAmount*/ 1.0f, /*enrgFactor*/ 0.3f, /*ACTime*/ - 1.0f, /*dirTendIgnore*/ false, /*dirTendImpactOnScoreRatio*/ - 0.7f, /*songScoreRatio*/ 0.0f);
//
// EXPECT_EQ(0.0f, score);
#endif // ITF_USE_MOVESPACEGESTURE
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// teardown
// -----------------------------------------------------------------------------------------------------------------------------------------------------
delete moveInterface;
DESTROY_CLASS_SINGLETON(JD_GameContextManager_Mock);
DESTROY_CLASS_SINGLETON(JD_GameManager_Mock);
DESTROY_CLASS_SINGLETON(TapeEventBroadcaster_Mock);
DESTROY_CLASS_SINGLETON(XMLConfig);
}
}
#endif // defined( ITF_USE_MOVESPACEGESTURE )