Environment.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <AzCore/UnitTest/TestTypes.h>
  9. #include <AzTest/AzTest.h>
  10. #include <AzCore/Memory/SystemAllocator.h>
  11. #include <AzFramework/Application/Application.h>
  12. #include <Tests/Environment.h>
  13. namespace NumericalMethods
  14. {
  15. void ExpectClose(const VectorVariable& actual, const VectorVariable& expected, double tolerance)
  16. {
  17. ASSERT_TRUE(actual.GetDimension() == expected.GetDimension());
  18. for (AZ::u32 i = 0; i < actual.GetDimension(); i++)
  19. {
  20. EXPECT_NEAR(actual[i], expected[i], tolerance);
  21. }
  22. }
  23. void ExpectClose(const AZStd::vector<double>& actual, const AZStd::vector<double>& expected, double tolerance)
  24. {
  25. ASSERT_TRUE(actual.size() == expected.size());
  26. for (AZ::u32 i = 0; i < actual.size(); i++)
  27. {
  28. EXPECT_NEAR(actual[i], expected[i], tolerance);
  29. }
  30. }
  31. // Global test environment.
  32. class NumericalMethodsTestEnvironment
  33. : public AZ::Test::ITestEnvironment
  34. {
  35. protected:
  36. void SetupEnvironment() override;
  37. void TeardownEnvironment() override;
  38. AZ::ComponentApplication* m_application;
  39. AZ::Entity* m_systemEntity;
  40. };
  41. void NumericalMethodsTestEnvironment::SetupEnvironment()
  42. {
  43. // Create application and descriptor
  44. m_application = aznew AZ::ComponentApplication;
  45. AZ::ComponentApplication::Descriptor appDesc;
  46. appDesc.m_useExistingAllocator = true;
  47. // Create system entity
  48. AZ::ComponentApplication::StartupParameters startupParams;
  49. m_systemEntity = m_application->Create(appDesc, startupParams);
  50. AZ_TEST_ASSERT(m_systemEntity);
  51. m_systemEntity->Init();
  52. m_systemEntity->Activate();
  53. }
  54. void NumericalMethodsTestEnvironment::TeardownEnvironment()
  55. {
  56. delete m_application;
  57. }
  58. } // namespace NumericalMethods
  59. AZ_UNIT_TEST_HOOK(new NumericalMethods::NumericalMethodsTestEnvironment);