Awesome, thank you so much @Mhousse1247 , that looks rock solid.
I thought this code as so worthy that I’ve taken the liberty of writing a test for it.
MiscTest.cpp
#include "mxbox.h"
#include "AutomationTest.h"
#include "MXBlueprintFunctionLibrary.h"
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FMiscTest, "mxbox.MiscTest", EAutomationTestFlags::ApplicationContextMask | EAutomationTestFlags::ProductFilter)
bool FMiscTest::RunTest(const FString& Parameters)
{
TArray<FRotator> RotationArray;
RotationArray.Push(FRotator(0.f , 0.f , 0.f));
RotationArray.Push(FRotator(0.f , 0.f , 90.f));
RotationArray.Push(FRotator(0.f , 90.f , 180.f));
RotationArray.Push(FRotator(90.f, 180.f, 270.f));
TestEqual(TEXT("Testing GetClosestRotationIndex 0"), UMXBlueprintFunctionLibrary::GetClosestRotationIndex(FRotator(0.f , 11.f , 20.f ), RotationArray), 0);
TestEqual(TEXT("Testing GetClosestRotationIndex 1"), UMXBlueprintFunctionLibrary::GetClosestRotationIndex(FRotator(0.f , 0.f , 95.f ), RotationArray), 1);
TestEqual(TEXT("Testing GetClosestRotationIndex 2"), UMXBlueprintFunctionLibrary::GetClosestRotationIndex(FRotator(0.f , 93.f , 186.f), RotationArray), 2);
TestEqual(TEXT("Testing GetClosestRotationIndex 3"), UMXBlueprintFunctionLibrary::GetClosestRotationIndex(FRotator(80.f, 180.f, 240.f), RotationArray), 3);
return true;
}
Please note, to any passers by, this is my first ever unit test - so please tread with caution (and please feel free to critique)
If anybody needs help implementing this, please shout and I’ll be happy to help.
Best,
James