Switched GradientSignal to use GemTestEnvironment. (#6886)

This allows actual Shape components to be used instead of MockShapes, which is important for the benchmarks to get accurate results as Mocks are extremely expensive.  It also removes a lot of unnecessary mock handling and test setup code.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
Mike Balfour
2022-01-13 14:44:59 -06:00
committed by GitHub
parent a99bf8ff1a
commit 62e7483b0e
9 changed files with 193 additions and 220 deletions
@@ -27,14 +27,12 @@ namespace UnitTest
void TestLevelsGradientComponent(int dataSize, const AZStd::vector<float>& inputData, const AZStd::vector<float>& expectedOutput,
float inputMin, float inputMid, float inputMax, float outputMin, float outputMax)
{
auto entityMock = CreateEntity();
auto entityMock = CreateTestEntity(1.0f);
const AZ::EntityId id = entityMock->GetId();
UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
GradientSignal::GradientTransformConfig gradientTransformConfig;
CreateComponent<GradientSignal::GradientTransformComponent>(entityMock.get(), gradientTransformConfig);
CreateComponent<MockShapeComponent>(entityMock.get());
MockShapeComponentHandler mockShapeHandler(entityMock->GetId());
entityMock->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
ActivateEntity(entityMock.get());
@@ -47,7 +45,7 @@ namespace UnitTest
config.m_outputMax = outputMax;
auto entity = CreateEntity();
CreateComponent<GradientSignal::LevelsGradientComponent>(entity.get(), config);
entity->CreateComponent<GradientSignal::LevelsGradientComponent>(config);
ActivateEntity(entity.get());
TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
@@ -56,14 +54,12 @@ namespace UnitTest
void TestPosterizeGradientComponent(int dataSize, const AZStd::vector<float>& inputData, const AZStd::vector<float>& expectedOutput,
GradientSignal::PosterizeGradientConfig::ModeType posterizeMode, int bands)
{
auto entityMock = CreateEntity();
auto entityMock = CreateTestEntity(0.5f);
const AZ::EntityId id = entityMock->GetId();
UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
GradientSignal::GradientTransformConfig gradientTransformConfig;
CreateComponent<GradientSignal::GradientTransformComponent>(entityMock.get(), gradientTransformConfig);
CreateComponent<MockShapeComponent>(entityMock.get());
MockShapeComponentHandler mockShapeHandler(entityMock->GetId());
entityMock->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
ActivateEntity(entityMock.get());
@@ -73,7 +69,7 @@ namespace UnitTest
config.m_bands = bands;
auto entity = CreateEntity();
CreateComponent<GradientSignal::PosterizeGradientComponent>(entity.get(), config);
entity->CreateComponent<GradientSignal::PosterizeGradientComponent>(config);
ActivateEntity(entity.get());
TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
@@ -82,14 +78,12 @@ namespace UnitTest
void TestSmoothStepGradientComponent(int dataSize, const AZStd::vector<float>& inputData, const AZStd::vector<float>& expectedOutput,
float midpoint, float range, float softness)
{
auto entityMock = CreateEntity();
auto entityMock = CreateTestEntity(0.5f);
const AZ::EntityId id = entityMock->GetId();
UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
GradientSignal::GradientTransformConfig gradientTransformConfig;
CreateComponent<GradientSignal::GradientTransformComponent>(entityMock.get(), gradientTransformConfig);
CreateComponent<MockShapeComponent>(entityMock.get());
MockShapeComponentHandler mockShapeHandler(entityMock->GetId());
entityMock->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
ActivateEntity(entityMock.get());
@@ -100,7 +94,7 @@ namespace UnitTest
config.m_smoothStep.m_falloffStrength = softness;
auto entity = CreateEntity();
CreateComponent<GradientSignal::SmoothStepGradientComponent>(entity.get(), config);
entity->CreateComponent<GradientSignal::SmoothStepGradientComponent>(config);
ActivateEntity(entity.get());
TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
@@ -108,14 +102,12 @@ namespace UnitTest
void TestThresholdGradientComponent(int dataSize, const AZStd::vector<float>& inputData, const AZStd::vector<float>& expectedOutput, float threshold)
{
auto entityMock = CreateEntity();
auto entityMock = CreateTestEntity(0.5f);
const AZ::EntityId id = entityMock->GetId();
UnitTest::MockGradientArrayRequestsBus mockGradientRequestsBus(id, inputData, dataSize);
GradientSignal::GradientTransformConfig gradientTransformConfig;
CreateComponent<GradientSignal::GradientTransformComponent>(entityMock.get(), gradientTransformConfig);
CreateComponent<MockShapeComponent>(entityMock.get());
MockShapeComponentHandler mockShapeHandler(entityMock->GetId());
entityMock->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
ActivateEntity(entityMock.get());
@@ -124,7 +116,7 @@ namespace UnitTest
config.m_threshold = threshold;
auto entity = CreateEntity();
CreateComponent<GradientSignal::ThresholdGradientComponent>(entity.get(), config);
entity->CreateComponent<GradientSignal::ThresholdGradientComponent>(config);
ActivateEntity(entity.get());
TestFixedDataSampler(expectedOutput, dataSize, entity->GetId());
@@ -167,11 +159,11 @@ namespace UnitTest
AZStd::vector<float> expectedOutput = { AZ_TRAIT_UNIT_TEST_PERLINE_GRADIANT_GOLDEN_VALUES_7878 };
auto entity = CreateEntity();
CreateComponent<GradientSignal::PerlinGradientComponent>(entity.get(), config);
entity->CreateComponent<GradientSignal::PerlinGradientComponent>(config);
GradientSignal::GradientTransformConfig gradientTransformConfig;
CreateComponent<GradientSignal::GradientTransformComponent>(entity.get(), gradientTransformConfig);
CreateComponent<MockShapeComponent>(entity.get());
entity->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
entity->CreateComponent<MockShapeComponent>();
MockShapeComponentHandler mockShapeHandler(entity->GetId());
ActivateEntity(entity.get());
@@ -197,11 +189,11 @@ namespace UnitTest
config.m_randomSeed = 5656;
auto entity = CreateEntity();
CreateComponent<GradientSignal::RandomGradientComponent>(entity.get(), config);
entity->CreateComponent<GradientSignal::RandomGradientComponent>(config);
GradientSignal::GradientTransformConfig gradientTransformConfig;
CreateComponent<GradientSignal::GradientTransformComponent>(entity.get(), gradientTransformConfig);
CreateComponent<MockShapeComponent>(entity.get());
entity->CreateComponent<GradientSignal::GradientTransformComponent>(gradientTransformConfig);
entity->CreateComponent<MockShapeComponent>();
MockShapeComponentHandler mockShapeHandler(entity->GetId());
ActivateEntity(entity.get());
@@ -546,4 +538,5 @@ namespace UnitTest
}
}
AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
// This uses custom test / benchmark hooks so that we can load LmbrCentral and use Shape components in our unit tests and benchmarks.
AZ_UNIT_TEST_HOOK(new UnitTest::GradientSignalTestEnvironment, UnitTest::GradientSignalBenchmarkEnvironment);