Skip to content

Commit

Permalink
Add comparing primitive number types for order.
Browse files Browse the repository at this point in the history
  • Loading branch information
npruehs committed May 15, 2020
1 parent 730a597 commit 889aca7
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatEqual =
const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatNotEqual =
TEXT("Assertion failed - {0} - Was {1}, but should not be.");

const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatLessThan =
TEXT("Assertion failed - {0} - Expected: {1} < {2}, but was not.");

const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatLessThanOrEqualTo =
TEXT("Assertion failed - {0} - Expected: {1} <= {2}, but was not.");

const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatGreaterThan =
TEXT("Assertion failed - {0} - Expected: {1} > {2}, but was not.");

const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatGreaterThanOrEqualTo =
TEXT("Assertion failed - {0} - Expected: {1} >= {2}, but was not.");

const FString UDaeTestAssertBlueprintFunctionLibrary::ErrorMessageFormatInRange =
TEXT("Assertion failed - {0} - Expected: between {1} and {2}, but was: {3}");

Expand Down Expand Up @@ -126,6 +138,14 @@ void UDaeTestAssertBlueprintFunctionLibrary::AssertNotEqualByte(uint8 Actual, ui
AssertNotEqual(Context, What, Actual, Unexpected);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertCompareByte(uint8 First,
EDaeTestComparisonMethod ShouldBe,
uint8 Second, const FString& What,
UObject* Context /*= nullptr*/)
{
AssertCompare(Context, What, First, ShouldBe, Second);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertEqualInt32(int32 Actual, int32 Expected,
const FString& What,
UObject* Context /*= nullptr*/)
Expand All @@ -140,6 +160,14 @@ void UDaeTestAssertBlueprintFunctionLibrary::AssertNotEqualInt32(int32 Actual, i
AssertNotEqual(Context, What, Actual, Unexpected);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertCompareInt32(int32 First,
EDaeTestComparisonMethod ShouldBe,
int32 Second, const FString& What,
UObject* Context /*= nullptr*/)
{
AssertCompare(Context, What, First, ShouldBe, Second);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertEqualInt64(int64 Actual, int64 Expected,
const FString& What,
UObject* Context /*= nullptr*/)
Expand All @@ -154,6 +182,14 @@ void UDaeTestAssertBlueprintFunctionLibrary::AssertNotEqualInt64(int64 Actual, i
AssertNotEqual(Context, What, Actual, Unexpected);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertCompareInt64(int64 First,
EDaeTestComparisonMethod ShouldBe,
int64 Second, const FString& What,
UObject* Context /*= nullptr*/)
{
AssertCompare(Context, What, First, ShouldBe, Second);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertEqualFloat(float Actual, float Expected,
const FString& What,
UObject* Context /*= nullptr*/)
Expand All @@ -176,6 +212,14 @@ void UDaeTestAssertBlueprintFunctionLibrary::AssertNotEqualFloat(float Actual, f
}
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertCompareFloat(float First,
EDaeTestComparisonMethod ShouldBe,
float Second, const FString& What,
UObject* Context /*= nullptr*/)
{
AssertCompare(Context, What, First, ShouldBe, Second);
}

void UDaeTestAssertBlueprintFunctionLibrary::AssertEqualName(const FName& Actual,
const FName& Expected,
bool bIgnoreCase, const FString& What,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "DaeTestComparisonMethod.h"
#include <CoreMinimal.h>
#include <Kismet/BlueprintFunctionLibrary.h>
#include "DaeTestAssertBlueprintFunctionLibrary.generated.h"
Expand Down Expand Up @@ -60,6 +61,12 @@ class DAEDALICTESTAUTOMATIONPLUGIN_API UDaeTestAssertBlueprintFunctionLibrary
static void AssertNotEqualByte(uint8 Actual, uint8 Unexpected, const FString& What,
UObject* Context = nullptr);

/** Compares the specified bytes for order. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Compare (Byte)"))
static void AssertCompareByte(uint8 First, EDaeTestComparisonMethod ShouldBe, uint8 Second,
const FString& What, UObject* Context = nullptr);

/** Expects the specified 32-bit integers to be equal. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Equal (Integer)"))
Expand All @@ -72,6 +79,12 @@ class DAEDALICTESTAUTOMATIONPLUGIN_API UDaeTestAssertBlueprintFunctionLibrary
static void AssertNotEqualInt32(int32 Actual, int32 Unexpected, const FString& What,
UObject* Context = nullptr);

/** Compares the specified 32-bit integers for order. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Compare (Integer)"))
static void AssertCompareInt32(int32 First, EDaeTestComparisonMethod ShouldBe, int32 Second,
const FString& What, UObject* Context = nullptr);

/** Expects the specified 64-bit integers to be equal. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Equal (Integer64)"))
Expand All @@ -84,6 +97,12 @@ class DAEDALICTESTAUTOMATIONPLUGIN_API UDaeTestAssertBlueprintFunctionLibrary
static void AssertNotEqualInt64(int64 Actual, int64 Unexpected, const FString& What,
UObject* Context = nullptr);

/** Compares the specified 64-bit integers for order. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Compare (Integer64)"))
static void AssertCompareInt64(int64 First, EDaeTestComparisonMethod ShouldBe, int64 Second,
const FString& What, UObject* Context = nullptr);

/** Expects the specified floats to be (nearly) equal. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Equal (Float)"))
Expand All @@ -96,6 +115,12 @@ class DAEDALICTESTAUTOMATIONPLUGIN_API UDaeTestAssertBlueprintFunctionLibrary
static void AssertNotEqualFloat(float Actual, float Unexpected, const FString& What,
UObject* Context = nullptr);

/** Compares the specified floats for order. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Compare (Float)"))
static void AssertCompareFloat(float First, EDaeTestComparisonMethod ShouldBe, float Second,
const FString& What, UObject* Context = nullptr);

/** Expects the specified names to be equal. */
UFUNCTION(BlueprintCallable, meta = (HidePin = "Context", DefaultToSelf = "Context",
DisplayName = "Assert Equal (Name)"))
Expand Down Expand Up @@ -239,6 +264,10 @@ class DAEDALICTESTAUTOMATIONPLUGIN_API UDaeTestAssertBlueprintFunctionLibrary
private:
static const FString ErrorMessageFormatEqual;
static const FString ErrorMessageFormatNotEqual;
static const FString ErrorMessageFormatLessThan;
static const FString ErrorMessageFormatLessThanOrEqualTo;
static const FString ErrorMessageFormatGreaterThan;
static const FString ErrorMessageFormatGreaterThanOrEqualTo;
static const FString ErrorMessageFormatInRange;
static const FString ErrorMessageFormatNotInRange;

Expand All @@ -263,4 +292,59 @@ class DAEDALICTESTAUTOMATIONPLUGIN_API UDaeTestAssertBlueprintFunctionLibrary
OnTestFailed(Context, Message);
}
}

template<typename T>
static void AssertCompare(UObject* Context, const FString& What, T First,
EDaeTestComparisonMethod ShouldBe, T Second)
{
bool bFulfilled = false;

switch (ShouldBe)
{
case EDaeTestComparisonMethod::LessThan:
bFulfilled = First < Second;
break;

case EDaeTestComparisonMethod::LessThanOrEqualTo:
bFulfilled = First <= Second;
break;

case EDaeTestComparisonMethod::GreaterThanOrEqualTo:
bFulfilled = First >= Second;
break;

case EDaeTestComparisonMethod::GreaterThan:
bFulfilled = First > Second;
break;
}

if (bFulfilled)
{
return;
}

FString FormatString;

switch (ShouldBe)
{
case EDaeTestComparisonMethod::LessThan:
FormatString = ErrorMessageFormatLessThan;
break;

case EDaeTestComparisonMethod::LessThanOrEqualTo:
FormatString = ErrorMessageFormatLessThanOrEqualTo;
break;

case EDaeTestComparisonMethod::GreaterThanOrEqualTo:
FormatString = ErrorMessageFormatGreaterThanOrEqualTo;
break;

case EDaeTestComparisonMethod::GreaterThan:
FormatString = ErrorMessageFormatGreaterThan;
break;
}

FString Message = FString::Format(*FormatString, {What, First, Second});
OnTestFailed(Context, Message);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "DaeTestComparisonMethod.generated.h"

UENUM(BlueprintType)
enum class EDaeTestComparisonMethod : uint8
{
LessThan,
LessThanOrEqualTo,
GreaterThanOrEqualTo,
GreaterThan
};

0 comments on commit 889aca7

Please sign in to comment.