UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TestUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "CoreTypes.h"
8
9namespace Test
10{
11void ResetRandomSeed();
12
18
23template <typename T>
25{
26 TArray<T> Result;
27 if (InArray.Num() > 1 && Size < InArray.Num())
28 {
29 Result.Reset(Size);
30 while (Result.Num() < Size)
31 {
32 const int32 i = FMath::RandRange(0, InArray.Num() - 1);
33 if (Result.Find(InArray[i]) == INDEX_NONE)
34 {
35 Result.Add(InArray[i]);
36 }
37 }
38 }
39 return Result;
40}
41
45template <typename T>
47{
48 if (OutArray.Num() > 1)
49 {
50 for (int32 i = 0; i < OutArray.Num(); i++)
51 {
52 const int32 j = FMath::RandRange(i, OutArray.Num() - 1);
53 if (i != j)
54 {
55 OutArray.Swap(i, j);
56 }
57 }
58 }
59}
60} // namespace Test
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
Definition Array.h:670
CORE_API void Reset(int32 NewReservedSize=0)
Definition String.cpp.inl:326
int32 Find(CharRangeType &&SubStr, ESearchCase::Type SearchCase=ESearchCase::IgnoreCase, ESearchDir::Type SearchDir=ESearchDir::FromStart, int32 StartPosition=INDEX_NONE) const
Definition UnrealString.h.inl:1116
Definition TestUtils.cpp:8
void ResetRandomSeed()
Definition TestUtils.cpp:12
TArray< int32 > MakeIndexArray(int32 Size)
Definition TestUtils.cpp:17
void Shuffle(TArray< T > &OutArray)
Definition TestUtils.h:46
TArray< T > MakeRandomSubset(const TArray< T > &InArray, int32 Size)
Definition TestUtils.h:24
static int32 RandRange(int32 Min, int32 Max)
Definition UnrealMathUtility.h:289