GradientSignalGetValuesTests.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Tests/GradientSignalTestFixtures.h>
  9. #include <Tests/GradientSignalTestHelpers.h>
  10. #include <AzTest/AzTest.h>
  11. namespace UnitTest
  12. {
  13. struct GradientSignalGetValuesTestsFixture
  14. : public GradientSignalTest
  15. {
  16. // Create an arbitrary size shape for comparing values within. It should be large enough that we detect any value anomalies
  17. // but small enough that the tests run quickly.
  18. const float TestShapeHalfBounds = 128.0f;
  19. };
  20. TEST_F(GradientSignalGetValuesTestsFixture, ImageGradientComponent_VerifyGetValueAndGetValuesMatch)
  21. {
  22. auto entity = BuildTestImageGradient(TestShapeHalfBounds);
  23. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  24. }
  25. TEST_F(GradientSignalGetValuesTestsFixture, PerlinGradientComponent_VerifyGetValueAndGetValuesMatch)
  26. {
  27. auto entity = BuildTestPerlinGradient(TestShapeHalfBounds);
  28. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  29. }
  30. TEST_F(GradientSignalGetValuesTestsFixture, RandomGradientComponent_VerifyGetValueAndGetValuesMatch)
  31. {
  32. auto entity = BuildTestRandomGradient(TestShapeHalfBounds);
  33. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  34. }
  35. TEST_F(GradientSignalGetValuesTestsFixture, ConstantGradientComponent_VerifyGetValueAndGetValuesMatch)
  36. {
  37. auto entity = BuildTestConstantGradient(TestShapeHalfBounds);
  38. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  39. }
  40. TEST_F(GradientSignalGetValuesTestsFixture, ShapeAreaFalloffGradientComponent_VerifyGetValueAndGetValuesMatch)
  41. {
  42. auto entity = BuildTestShapeAreaFalloffGradient(TestShapeHalfBounds);
  43. // Use a query range larger than our shape to ensure that we're getting falloff values within our query bounds.
  44. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), -TestShapeHalfBounds, TestShapeHalfBounds * 3.0f);
  45. }
  46. TEST_F(GradientSignalGetValuesTestsFixture, DitherGradientComponent_VerifyGetValueAndGetValuesMatch)
  47. {
  48. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  49. auto entity = BuildTestDitherGradient(TestShapeHalfBounds, baseEntity->GetId());
  50. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  51. }
  52. TEST_F(GradientSignalGetValuesTestsFixture, InvertGradientComponent_VerifyGetValueAndGetValuesMatch)
  53. {
  54. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  55. auto entity = BuildTestInvertGradient(TestShapeHalfBounds, baseEntity->GetId());
  56. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  57. }
  58. TEST_F(GradientSignalGetValuesTestsFixture, LevelsGradientComponent_VerifyGetValueAndGetValuesMatch)
  59. {
  60. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  61. auto entity = BuildTestLevelsGradient(TestShapeHalfBounds, baseEntity->GetId());
  62. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  63. }
  64. TEST_F(GradientSignalGetValuesTestsFixture, MixedGradientComponent_VerifyGetValueAndGetValuesMatch)
  65. {
  66. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  67. auto mixedEntity = BuildTestConstantGradient(TestShapeHalfBounds);
  68. auto entity = BuildTestMixedGradient(TestShapeHalfBounds, baseEntity->GetId(), mixedEntity->GetId());
  69. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  70. }
  71. TEST_F(GradientSignalGetValuesTestsFixture, PosterizeGradientComponent_VerifyGetValueAndGetValuesMatch)
  72. {
  73. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  74. auto entity = BuildTestPosterizeGradient(TestShapeHalfBounds, baseEntity->GetId());
  75. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  76. }
  77. TEST_F(GradientSignalGetValuesTestsFixture, ReferenceGradientComponent_VerifyGetValueAndGetValuesMatch)
  78. {
  79. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  80. auto entity = BuildTestReferenceGradient(TestShapeHalfBounds, baseEntity->GetId());
  81. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  82. }
  83. TEST_F(GradientSignalGetValuesTestsFixture, SmoothStepGradientComponent_VerifyGetValueAndGetValuesMatch)
  84. {
  85. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  86. auto entity = BuildTestSmoothStepGradient(TestShapeHalfBounds, baseEntity->GetId());
  87. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  88. }
  89. TEST_F(GradientSignalGetValuesTestsFixture, ThresholdGradientComponent_VerifyGetValueAndGetValuesMatch)
  90. {
  91. auto baseEntity = BuildTestRandomGradient(TestShapeHalfBounds);
  92. auto entity = BuildTestThresholdGradient(TestShapeHalfBounds, baseEntity->GetId());
  93. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  94. }
  95. TEST_F(GradientSignalGetValuesTestsFixture, SurfaceAltitudeGradientComponent_VerifyGetValueAndGetValuesMatch)
  96. {
  97. auto entity = BuildTestSurfaceAltitudeGradient(TestShapeHalfBounds);
  98. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  99. }
  100. TEST_F(GradientSignalGetValuesTestsFixture, SurfaceMaskGradientComponent_VerifyGetValueAndGetValuesMatch)
  101. {
  102. auto entity = BuildTestSurfaceMaskGradient(TestShapeHalfBounds);
  103. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  104. }
  105. TEST_F(GradientSignalGetValuesTestsFixture, SurfaceSlopeGradientComponent_VerifyGetValueAndGetValuesMatch)
  106. {
  107. auto entity = BuildTestSurfaceSlopeGradient(TestShapeHalfBounds);
  108. GradientSignalTestHelpers::CompareGetValueAndGetValues(entity->GetId(), 0.0f, TestShapeHalfBounds * 2.0f);
  109. }
  110. }