diff --git a/Redcraft.Utility/Source/Private/Testing/AssertionMacrosTesting.cpp b/Redcraft.Utility/Source/Private/Testing/AssertionMacrosTesting.cpp deleted file mode 100644 index 5624558..0000000 --- a/Redcraft.Utility/Source/Private/Testing/AssertionMacrosTesting.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "Testing/AssertionMacrosTesting.h" -#include "Miscellaneous/AssertionMacros.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -void TestNoEntry() -{ - check_no_entry(); - always_check_no_entry(); -} - -void TestNoReentry() -{ - check_no_reentry(); - always_check_no_reentry(); -} - -void TestNoRecursion(int32 Depth) -{ - if (Depth < 0) return; - - check_no_recursion(); - always_check_no_recursion(); - - TestNoRecursion(--Depth); -} - -void TestUnimplemented() -{ - unimplemented(); - always_unimplemented(); -} - -void TestAssertionMacros() -{ - check(true); - //check(false); - checkf(true, "True!"); - //checkf(false, "False!"); - - always_check(true); - //always_check(false); - always_checkf(true, "True!"); - //always_checkf(false, "False!"); - - //TestNoEntry(); - - TestNoReentry(); - //TestNoReentry(); - - TestNoRecursion(0); - TestNoRecursion(0); - //TestNoRecursion(1); - - //TestUnimplemented(); - - verify(true); - //verify(false); - - int32 A = 1; - int32 B = 0; - verify(B = A); - always_check(B == A); -} - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp b/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp new file mode 100644 index 0000000..382156d --- /dev/null +++ b/Redcraft.Utility/Source/Private/Testing/MiscellaneousTesting.cpp @@ -0,0 +1,209 @@ +#include "Testing/MiscellaneousTesting.h" +#include "Miscellaneous/AssertionMacros.h" +#include "Miscellaneous/Compare.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +void TestMiscellaneous() +{ + TestAssertionMacros(); + TestCompare(); +} + +NAMESPACE_PRIVATE_BEGIN + +void TestNoEntry() +{ + check_no_entry(); + always_check_no_entry(); +} + +void TestNoReentry() +{ + check_no_reentry(); + always_check_no_reentry(); +} + +void TestNoRecursion(int32 Depth) +{ + if (Depth < 0) return; + + check_no_recursion(); + always_check_no_recursion(); + + TestNoRecursion(--Depth); +} + +void TestUnimplemented() +{ + unimplemented(); + always_unimplemented(); +} + +NAMESPACE_PRIVATE_END + +void TestAssertionMacros() +{ + check(true); + //check(false); + checkf(true, "True!"); + //checkf(false, "False!"); + + always_check(true); + //always_check(false); + always_checkf(true, "True!"); + //always_checkf(false, "False!"); + + //NAMESPACE_PRIVATE::TestNoEntry(); + + NAMESPACE_PRIVATE::TestNoReentry(); + //NAMESPACE_PRIVATE::TestNoReentry(); + + NAMESPACE_PRIVATE::TestNoRecursion(0); + NAMESPACE_PRIVATE::TestNoRecursion(0); + //NAMESPACE_PRIVATE::TestNoRecursion(1); + + //NAMESPACE_PRIVATE::TestUnimplemented(); + + verify(true); + //verify(false); + + int32 A = 1; + int32 B = 0; + verify(B = A); + always_check(B == A); +} + +NAMESPACE_UNNAMED_BEGIN + +struct FTestPartialOrdering +{ + int32 Num; + bool bIsValid; + FTestPartialOrdering(int32 InNum, bool bInIsValid = true) : Num(InNum), bIsValid(bInIsValid) { } + friend bool operator==(FTestPartialOrdering LHS, FTestPartialOrdering RHS) { return LHS.bIsValid && RHS.bIsValid ? LHS.Num == RHS.Num : false; } + friend partial_ordering operator<=>(FTestPartialOrdering LHS, FTestPartialOrdering RHS) { return LHS.bIsValid && RHS.bIsValid ? LHS.Num <=> RHS.Num : partial_ordering::unordered; } +}; + +struct FTestWeakOrdering +{ + int32 Num; + FTestWeakOrdering(int32 InNum) : Num(InNum) { } + friend bool operator==(FTestWeakOrdering LHS, FTestWeakOrdering RHS) { return LHS.Num == RHS.Num; } + friend weak_ordering operator<=>(FTestWeakOrdering LHS, FTestWeakOrdering RHS) { return LHS.Num <=> RHS.Num; } +}; + +struct FTestStrongOrdering +{ + int32 Num; + FTestStrongOrdering(int32 InNum) : Num(InNum) { } + friend bool operator==(FTestStrongOrdering LHS, FTestStrongOrdering RHS) { return LHS.Num == RHS.Num; } + friend strong_ordering operator<=>(FTestStrongOrdering LHS, FTestStrongOrdering RHS) { return LHS.Num <=> RHS.Num; } +}; + +NAMESPACE_UNNAMED_END + +void TestCompare() +{ + always_check((-1 <=> 0) == strong_ordering::less); + always_check(( 0 <=> 0) == strong_ordering::equivalent); + always_check(( 0 <=> 0) == strong_ordering::equal); + always_check(( 0 <=> -1) == strong_ordering::greater); + + always_check((-1 <=> 0) < 0); + always_check((-1 <=> 0) <= 0); + always_check(( 0 <=> 0) <= 0); + always_check(( 0 <=> 0) == 0); + always_check(( 0 <=> 0) >= 0); + always_check(( 0 <=> -1) >= 0); + always_check(( 0 <=> -1) > 0); + always_check((-1 <=> 1) != 0); + + int64 NaNBit = 0xFFF8000000000000; + double NaN = *reinterpret_cast(&NaNBit); + + always_check((-1.0 <=> 0.0) == partial_ordering::less); + always_check(( 0.0 <=> 0.0) == partial_ordering::equivalent); + always_check(( 0.0 <=> -1.0) == partial_ordering::greater); + always_check(( 0.0 <=> NaN) == partial_ordering::unordered); + + always_check((-1.0 <=> 0.0) == weak_ordering::less); + always_check(( 0.0 <=> 0.0) == weak_ordering::equivalent); + always_check(( 0.0 <=> -1.0) == weak_ordering::greater); + + always_check((-1.0 <=> 0.0) == strong_ordering::less); + always_check(( 0.0 <=> 0.0) == strong_ordering::equivalent); + always_check(( 0.0 <=> 0.0) == strong_ordering::equal); + always_check(( 0.0 <=> -1.0) == strong_ordering::greater); + + always_check((-1.0 <=> 0.0) < 0); + always_check((-1.0 <=> 0.0) <= 0); + always_check(( 0.0 <=> 0.0) <= 0); + always_check(( 0.0 <=> 0.0) == 0); + always_check(( 0.0 <=> 0.0) >= 0); + always_check(( 0.0 <=> -1.0) >= 0); + always_check(( 0.0 <=> -1.0) > 0); + always_check((-1.0 <=> 1.0) != 0); + + always_check((FTestPartialOrdering(-1) <=> FTestPartialOrdering( 0)) == partial_ordering::less); + always_check((FTestPartialOrdering( 0) <=> FTestPartialOrdering( 0)) == partial_ordering::equivalent); + always_check((FTestPartialOrdering( 0) <=> FTestPartialOrdering(-1)) == partial_ordering::greater); + + always_check((FTestPartialOrdering( 0, true) <=> FTestPartialOrdering( 0, false)) == partial_ordering::unordered); + + always_check((FTestWeakOrdering(-1) <=> FTestWeakOrdering( 0)) == weak_ordering::less); + always_check((FTestWeakOrdering( 0) <=> FTestWeakOrdering( 0)) == weak_ordering::equivalent); + always_check((FTestWeakOrdering( 0) <=> FTestWeakOrdering(-1)) == weak_ordering::greater); + + always_check((FTestStrongOrdering(-1) <=> FTestStrongOrdering( 0)) == strong_ordering::less); + always_check((FTestStrongOrdering( 0) <=> FTestStrongOrdering( 0)) == strong_ordering::equivalent); + always_check((FTestStrongOrdering( 0) <=> FTestStrongOrdering( 0)) == strong_ordering::equal); + always_check((FTestStrongOrdering( 0) <=> FTestStrongOrdering(-1)) == strong_ordering::greater); + + always_check((FTestPartialOrdering(-1) < FTestPartialOrdering( 0))); + always_check((FTestPartialOrdering( 0) == FTestPartialOrdering( 0))); + always_check((FTestPartialOrdering( 0) > FTestPartialOrdering(-1))); + + always_check((FTestWeakOrdering(-1) < FTestWeakOrdering( 0))); + always_check((FTestWeakOrdering( 0) == FTestWeakOrdering( 0))); + always_check((FTestWeakOrdering( 0) > FTestWeakOrdering(-1))); + + always_check((FTestStrongOrdering(-1) < FTestStrongOrdering( 0))); + always_check((FTestStrongOrdering( 0) == FTestStrongOrdering( 0))); + always_check((FTestStrongOrdering( 0) > FTestStrongOrdering(-1))); + + always_check((TIsSame::Type, strong_ordering >::Value)); + always_check((TIsSame::Type, weak_ordering >::Value)); + always_check((TIsSame::Type, partial_ordering>::Value)); + + always_check(CThreeWayComparable); + always_check(CThreeWayComparable); + always_check(CThreeWayComparable); + always_check(CThreeWayComparable); + + always_check((CThreeWayComparableWith)); + always_check((CThreeWayComparableWith)); + + always_check((TIsSame::Type, strong_ordering >::Value)); + always_check((TIsSame::Type, partial_ordering>::Value)); + always_check((TIsSame::Type, partial_ordering>::Value)); + always_check((TIsSame::Type, weak_ordering >::Value)); + always_check((TIsSame::Type, strong_ordering >::Value)); + + always_check((TCompareThreeWay()(0, 0) == strong_ordering::equal)); + always_check((TCompareThreeWay() (0, 0.0) == strong_ordering::equal)); + + always_check((StrongOrder(0, 0) == strong_ordering::equal)); + always_check((WeakOrder(0, 0) == strong_ordering::equal)); + always_check((PartialOrder(0, 0) == strong_ordering::equal)); + always_check((CompareStrongOrderFallback(0, 0) == strong_ordering::equal)); + always_check((CompareWeakOrderFallback(0, 0) == strong_ordering::equal)); + always_check((ComparePartialOrderFallback(0, 0) == strong_ordering::equal)); + +} + +NAMESPACE_MODULE_END(Utility) +NAMESPACE_MODULE_END(Redcraft) +NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp index 30e2532..c9ada7d 100644 --- a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp @@ -1,5 +1,6 @@ #include "Testing/TemplatesTesting.h" #include "Miscellaneous/AssertionMacros.h" +#include "Miscellaneous/Compare.h" #include "Templates/Templates.h" #pragma warning(disable : 4930) @@ -14,10 +15,9 @@ void TestTemplates() { TestInvoke(); TestReferenceWrapper(); - TestCompare(); TestOptional(); TestVariant(); - TestMiscellaneous(); + TestOther(); } NAMESPACE_UNNAMED_BEGIN @@ -73,134 +73,6 @@ void TestReferenceWrapper() always_check(ArrayA[2] == 6); } -NAMESPACE_UNNAMED_BEGIN - -struct FTestPartialOrdering -{ - int32 Num; - bool bIsValid; - FTestPartialOrdering(int32 InNum, bool bInIsValid = true) : Num(InNum), bIsValid(bInIsValid) { } - friend bool operator==(FTestPartialOrdering LHS, FTestPartialOrdering RHS) { return LHS.bIsValid && RHS.bIsValid ? LHS.Num == RHS.Num : false; } - friend partial_ordering operator<=>(FTestPartialOrdering LHS, FTestPartialOrdering RHS) { return LHS.bIsValid && RHS.bIsValid ? LHS.Num <=> RHS.Num : partial_ordering::unordered; } -}; - -struct FTestWeakOrdering -{ - int32 Num; - FTestWeakOrdering(int32 InNum) : Num(InNum) { } - friend bool operator==(FTestWeakOrdering LHS, FTestWeakOrdering RHS) { return LHS.Num == RHS.Num; } - friend weak_ordering operator<=>(FTestWeakOrdering LHS, FTestWeakOrdering RHS) { return LHS.Num <=> RHS.Num; } -}; - -struct FTestStrongOrdering -{ - int32 Num; - FTestStrongOrdering(int32 InNum) : Num(InNum) { } - friend bool operator==(FTestStrongOrdering LHS, FTestStrongOrdering RHS) { return LHS.Num == RHS.Num; } - friend strong_ordering operator<=>(FTestStrongOrdering LHS, FTestStrongOrdering RHS) { return LHS.Num <=> RHS.Num; } -}; - -NAMESPACE_UNNAMED_END - -void TestCompare() -{ - always_check((-1 <=> 0) == strong_ordering::less); - always_check(( 0 <=> 0) == strong_ordering::equivalent); - always_check(( 0 <=> 0) == strong_ordering::equal); - always_check(( 0 <=> -1) == strong_ordering::greater); - - always_check((-1 <=> 0) < 0); - always_check((-1 <=> 0) <= 0); - always_check(( 0 <=> 0) <= 0); - always_check(( 0 <=> 0) == 0); - always_check(( 0 <=> 0) >= 0); - always_check(( 0 <=> -1) >= 0); - always_check(( 0 <=> -1) > 0); - always_check((-1 <=> 1) != 0); - - int64 NaNBit = 0xFFF8000000000000; - double NaN = *reinterpret_cast(&NaNBit); - - always_check((-1.0 <=> 0.0) == partial_ordering::less); - always_check(( 0.0 <=> 0.0) == partial_ordering::equivalent); - always_check(( 0.0 <=> -1.0) == partial_ordering::greater); - always_check(( 0.0 <=> NaN) == partial_ordering::unordered); - - always_check((-1.0 <=> 0.0) == weak_ordering::less); - always_check(( 0.0 <=> 0.0) == weak_ordering::equivalent); - always_check(( 0.0 <=> -1.0) == weak_ordering::greater); - - always_check((-1.0 <=> 0.0) == strong_ordering::less); - always_check(( 0.0 <=> 0.0) == strong_ordering::equivalent); - always_check(( 0.0 <=> 0.0) == strong_ordering::equal); - always_check(( 0.0 <=> -1.0) == strong_ordering::greater); - - always_check((-1.0 <=> 0.0) < 0); - always_check((-1.0 <=> 0.0) <= 0); - always_check(( 0.0 <=> 0.0) <= 0); - always_check(( 0.0 <=> 0.0) == 0); - always_check(( 0.0 <=> 0.0) >= 0); - always_check(( 0.0 <=> -1.0) >= 0); - always_check(( 0.0 <=> -1.0) > 0); - always_check((-1.0 <=> 1.0) != 0); - - always_check((FTestPartialOrdering(-1) <=> FTestPartialOrdering( 0)) == partial_ordering::less); - always_check((FTestPartialOrdering( 0) <=> FTestPartialOrdering( 0)) == partial_ordering::equivalent); - always_check((FTestPartialOrdering( 0) <=> FTestPartialOrdering(-1)) == partial_ordering::greater); - - always_check((FTestPartialOrdering( 0, true) <=> FTestPartialOrdering( 0, false)) == partial_ordering::unordered); - - always_check((FTestWeakOrdering(-1) <=> FTestWeakOrdering( 0)) == weak_ordering::less); - always_check((FTestWeakOrdering( 0) <=> FTestWeakOrdering( 0)) == weak_ordering::equivalent); - always_check((FTestWeakOrdering( 0) <=> FTestWeakOrdering(-1)) == weak_ordering::greater); - - always_check((FTestStrongOrdering(-1) <=> FTestStrongOrdering( 0)) == strong_ordering::less); - always_check((FTestStrongOrdering( 0) <=> FTestStrongOrdering( 0)) == strong_ordering::equivalent); - always_check((FTestStrongOrdering( 0) <=> FTestStrongOrdering( 0)) == strong_ordering::equal); - always_check((FTestStrongOrdering( 0) <=> FTestStrongOrdering(-1)) == strong_ordering::greater); - - always_check((FTestPartialOrdering(-1) < FTestPartialOrdering( 0))); - always_check((FTestPartialOrdering( 0) == FTestPartialOrdering( 0))); - always_check((FTestPartialOrdering( 0) > FTestPartialOrdering(-1))); - - always_check((FTestWeakOrdering(-1) < FTestWeakOrdering( 0))); - always_check((FTestWeakOrdering( 0) == FTestWeakOrdering( 0))); - always_check((FTestWeakOrdering( 0) > FTestWeakOrdering(-1))); - - always_check((FTestStrongOrdering(-1) < FTestStrongOrdering( 0))); - always_check((FTestStrongOrdering( 0) == FTestStrongOrdering( 0))); - always_check((FTestStrongOrdering( 0) > FTestStrongOrdering(-1))); - - always_check((TIsSame::Type, strong_ordering >::Value)); - always_check((TIsSame::Type, weak_ordering >::Value)); - always_check((TIsSame::Type, partial_ordering>::Value)); - - always_check(CThreeWayComparable); - always_check(CThreeWayComparable); - always_check(CThreeWayComparable); - always_check(CThreeWayComparable); - - always_check((CThreeWayComparableWith)); - always_check((CThreeWayComparableWith)); - - always_check((TIsSame::Type, strong_ordering >::Value)); - always_check((TIsSame::Type, partial_ordering>::Value)); - always_check((TIsSame::Type, partial_ordering>::Value)); - always_check((TIsSame::Type, weak_ordering >::Value)); - always_check((TIsSame::Type, strong_ordering >::Value)); - - always_check((TCompareThreeWay()(0, 0) == strong_ordering::equal)); - always_check((TCompareThreeWay() (0, 0.0) == strong_ordering::equal)); - - always_check((StrongOrder(0, 0) == strong_ordering::equal)); - always_check((WeakOrder(0, 0) == strong_ordering::equal)); - always_check((PartialOrder(0, 0) == strong_ordering::equal)); - always_check((CompareStrongOrderFallback(0, 0) == strong_ordering::equal)); - always_check((CompareWeakOrderFallback(0, 0) == strong_ordering::equal)); - always_check((ComparePartialOrderFallback(0, 0) == strong_ordering::equal)); - -} - void TestOptional() { TOptional TempA; @@ -468,12 +340,12 @@ int32 TestFunctionB(T** Ptr) NAMESPACE_UNNAMED_END -void TestMiscellaneous() +void TestOther() { TTestStructA ObjectA(new int32(3)); always_check(TestFunctionB(&ObjectA) == 1); always_check(TestFunctionB(AddressOf(ObjectA)) == 0); - always_check(AddressOf(TestMiscellaneous) == &TestMiscellaneous); + always_check(AddressOf(TestOther) == &TestOther); } NAMESPACE_MODULE_END(Utility) diff --git a/Redcraft.Utility/Source/Public/Templates/Compare.h b/Redcraft.Utility/Source/Public/Miscellaneous/Compare.h similarity index 100% rename from Redcraft.Utility/Source/Public/Templates/Compare.h rename to Redcraft.Utility/Source/Public/Miscellaneous/Compare.h diff --git a/Redcraft.Utility/Source/Public/Templates/Optional.h b/Redcraft.Utility/Source/Public/Templates/Optional.h index 478c965..501dad5 100644 --- a/Redcraft.Utility/Source/Public/Templates/Optional.h +++ b/Redcraft.Utility/Source/Public/Templates/Optional.h @@ -1,7 +1,6 @@ #pragma once #include "CoreTypes.h" -#include "Templates/Compare.h" #include "Concepts/Comparable.h" #include "TypeTraits/TypeTraits.h" #include "Miscellaneous/AssertionMacros.h" diff --git a/Redcraft.Utility/Source/Public/Templates/Templates.h b/Redcraft.Utility/Source/Public/Templates/Templates.h index 7874eaa..e29a6cd 100644 --- a/Redcraft.Utility/Source/Public/Templates/Templates.h +++ b/Redcraft.Utility/Source/Public/Templates/Templates.h @@ -6,6 +6,5 @@ #include "Templates/Noncopyable.h" #include "Templates/Invoke.h" #include "Templates/ReferenceWrapper.h" -#include "Templates/Compare.h" #include "Templates/Optional.h" #include "Templates/Variant.h" diff --git a/Redcraft.Utility/Source/Public/Testing/AssertionMacrosTesting.h b/Redcraft.Utility/Source/Public/Testing/MiscellaneousTesting.h similarity index 75% rename from Redcraft.Utility/Source/Public/Testing/AssertionMacrosTesting.h rename to Redcraft.Utility/Source/Public/Testing/MiscellaneousTesting.h index ecc651b..9c4058c 100644 --- a/Redcraft.Utility/Source/Public/Testing/AssertionMacrosTesting.h +++ b/Redcraft.Utility/Source/Public/Testing/MiscellaneousTesting.h @@ -6,7 +6,9 @@ NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) +REDCRAFTUTILITY_API void TestMiscellaneous(); REDCRAFTUTILITY_API void TestAssertionMacros(); +REDCRAFTUTILITY_API void TestCompare(); NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) diff --git a/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h b/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h index a728eb8..c6b792d 100644 --- a/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h +++ b/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h @@ -9,10 +9,9 @@ NAMESPACE_MODULE_BEGIN(Utility) REDCRAFTUTILITY_API void TestTemplates(); REDCRAFTUTILITY_API void TestInvoke(); REDCRAFTUTILITY_API void TestReferenceWrapper(); -REDCRAFTUTILITY_API void TestCompare(); REDCRAFTUTILITY_API void TestOptional(); REDCRAFTUTILITY_API void TestVariant(); -REDCRAFTUTILITY_API void TestMiscellaneous(); +REDCRAFTUTILITY_API void TestOther(); NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft)