You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
#include <AzTest/AzTest.h>
|
|
#include <AzCore/Memory/SystemAllocator.h>
|
|
#include <AzCore/Memory/MemoryComponent.h>
|
|
#include <AzFramework/Application/Application.h>
|
|
#include <Tests/Environment.h>
|
|
|
|
namespace NumericalMethods
|
|
{
|
|
void ExpectClose(const VectorVariable& actual, const VectorVariable& expected, double tolerance)
|
|
{
|
|
ASSERT_TRUE(actual.GetDimension() == expected.GetDimension());
|
|
for (AZ::u32 i = 0; i < actual.GetDimension(); i++)
|
|
{
|
|
EXPECT_NEAR(actual[i], expected[i], tolerance);
|
|
}
|
|
}
|
|
|
|
void ExpectClose(const AZStd::vector<double>& actual, const AZStd::vector<double>& expected, double tolerance)
|
|
{
|
|
ASSERT_TRUE(actual.size() == expected.size());
|
|
for (AZ::u32 i = 0; i < actual.size(); i++)
|
|
{
|
|
EXPECT_NEAR(actual[i], expected[i], tolerance);
|
|
}
|
|
}
|
|
|
|
// Global test environment.
|
|
class NumericalMethodsTestEnvironment
|
|
: public AZ::Test::ITestEnvironment
|
|
{
|
|
protected:
|
|
void SetupEnvironment() override;
|
|
void TeardownEnvironment() override;
|
|
|
|
AZ::ComponentApplication* m_application;
|
|
AZ::Entity* m_systemEntity;
|
|
};
|
|
|
|
void NumericalMethodsTestEnvironment::SetupEnvironment()
|
|
{
|
|
#if AZ_TRAIT_UNITTEST_USE_TEST_RUNNER_ENVIRONMENT
|
|
AZ::EnvironmentInstance inst = AZ::Test::GetPlatform().GetTestRunnerEnvironment();
|
|
AZ::Environment::Attach(inst);
|
|
#endif
|
|
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
|
|
|
|
// Create application and descriptor
|
|
m_application = aznew AZ::ComponentApplication;
|
|
AZ::ComponentApplication::Descriptor appDesc;
|
|
appDesc.m_useExistingAllocator = true;
|
|
|
|
// Create system entity
|
|
AZ::ComponentApplication::StartupParameters startupParams;
|
|
m_systemEntity = m_application->Create(appDesc, startupParams);
|
|
AZ_TEST_ASSERT(m_systemEntity);
|
|
m_systemEntity->AddComponent(aznew AZ::MemoryComponent());
|
|
m_systemEntity->Init();
|
|
m_systemEntity->Activate();
|
|
}
|
|
|
|
void NumericalMethodsTestEnvironment::TeardownEnvironment()
|
|
{
|
|
delete m_application;
|
|
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
|
|
}
|
|
|
|
} // namespace NumericalMethods
|
|
|
|
AZ_UNIT_TEST_HOOK(new NumericalMethods::NumericalMethodsTestEnvironment);
|