Translated tests for Colliders/TrapazoidalPrismCollider

This commit is contained in:
Leonetienne 2022-02-11 15:50:15 +01:00
parent 7675422264
commit b77534a7a1
2 changed files with 158 additions and 159 deletions

View File

@ -29,6 +29,7 @@ add_executable(Tests
Random__RandomInteger.cpp Random__RandomInteger.cpp
Random__RandomRange.cpp Random__RandomRange.cpp
Random_RandomIntRange.cpp Random_RandomIntRange.cpp
TrapazoidalPrismCollider.cpp
) )
target_link_libraries(Tests Eule) target_link_libraries(Tests Eule)

View File

@ -1,34 +1,19 @@
#include "CppUnitTest.h" #include "Catch2.h"
#include "../Eule/TrapazoidalPrismCollider.h" #include <Eule/TrapazoidalPrismCollider.h>
#include "../Eule/Quaternion.h" #include <Eule/Quaternion.h>
#include "../_TestingUtilities/HandyMacros.h"
#include <random> #include <random>
#include <array> #include <array>
#include <sstream>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Eule; using namespace Eule;
using TPC = TrapazoidalPrismCollider; using TPC = TrapazoidalPrismCollider;
namespace Colliders namespace {
static std::mt19937 rng = std::mt19937((std::random_device())());
}
// Tests that all vertices can be set individually, and at once
TEST_CASE(__FILE__"/Can_Set_Each_Vertex", "[TrapazoidalPrismCollider][Collider]")
{ {
TEST_CLASS(_TrapazoidalPrismCollider)
{
private:
std::mt19937 rng;
public:
// Constructor
_TrapazoidalPrismCollider()
{
rng = std::mt19937((std::random_device())());
return;
}
// Tests that all vertices can be set individually, and at once
TEST_METHOD(Can_Set_Each_Vertex)
{
// All vertex values are unique // All vertex values are unique
TPC tpc; TPC tpc;
tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Vector3d(-1, -1, 1) * 1); tpc.SetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM, Vector3d(-1, -1, 1) * 1);
@ -40,24 +25,39 @@ namespace Colliders
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Vector3d(1, -1, -1) * 7); tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM, Vector3d(1, -1, -1) * 7);
tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Vector3d(1, 1, -1) * 8); tpc.SetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP, Vector3d(1, 1, -1) * 8);
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, 1) * 1), L"FRONT|LEFT|BOTTOM"); INFO("FRONT|LEFT|BOTTOM");
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, 1) * 2), L"FRONT|LEFT|TOP"); REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, 1) * 1));
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, -1) * 3), L"BACK|LEFT|BOTTOM");
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, -1) * 4), L"BACK|LEFT|TOP"); INFO("FRONT|LEFT|TOP");
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, 1) * 5), L"FRONT|RIGHT|BOTTOM"); REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, 1) * 2));
Assert::IsTrue(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, 1) * 6), L"FRONT|RIGHT|TOP");
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, -1) * 7), L"BACK|RIGHT|BOTTOM"); INFO("BACK|LEFT|BOTTOM");
Assert::IsTrue(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, -1) * 8), L"BACK|RIGHT|TOP"); REQUIRE(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::BOTTOM) == (Vector3d(-1, -1, -1) * 3));
INFO("BACK|LEFT|TOP");
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::LEFT | TPC::TOP) == (Vector3d(-1, 1, -1) * 4));
INFO("FRONT|RIGHT|BOTTOM");
REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, 1) * 5));
INFO("FRONT|RIGHT|TOP");
REQUIRE(tpc.GetVertex(TPC::FRONT | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, 1) * 6));
INFO("BACK|RIGHT|BOTTOM");
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::BOTTOM) == (Vector3d(1, -1, -1) * 7));
INFO("BACK|RIGHT|TOP");
REQUIRE(tpc.GetVertex(TPC::BACK | TPC::RIGHT | TPC::TOP) == (Vector3d(1, 1, -1) * 8));
return; return;
} }
// Tests that points inside work. // Tests that points inside work.
// For this, we define a few points around [0,0,0] and check if they are contained. // For this, we define a few points around [0,0,0] and check if they are contained.
// We then rotate the collider, and check again // We then rotate the collider, and check again
// Gets repeated for every possible rotation with a min-distance per axis of 2 deg // Gets repeated for every possible rotation with a min-distance per axis of 2 deg
TEST_METHOD(Points_Inside) TEST_CASE(__FILE__"/Points_Inside", "[TrapazoidalPrismCollider][Collider]")
{ {
// Setup // Setup
// Define known-inside points // Define known-inside points
std::array<Vector3d, 9> knownInsides = { std::array<Vector3d, 9> knownInsides = {
@ -78,7 +78,7 @@ namespace Colliders
// Exercise // Exercise
// Now check that these points are inside for all these possible angles // Now check that these points are inside for all these possible angles
#ifndef _DEBUG #ifndef _DEBUG
constexpr double stepSize = 2; constexpr double stepSize = 40;
#else #else
constexpr double stepSize = 32; constexpr double stepSize = 32;
#endif #endif
@ -99,18 +99,18 @@ namespace Colliders
// Verify // Verify
// Verify that all are inside // Verify that all are inside
for (const Vector3d& v : knownInsides) for (const Vector3d& v : knownInsides)
Assert::IsTrue(tpc.Contains(v)); REQUIRE(tpc.Contains(v));
} }
return; return;
} }
// Tests that points outside work. // Tests that points outside work.
// For this, we define a few points that are definitely outside for various reasons and check if they are not contained. // For this, we define a few points that are definitely outside for various reasons and check if they are not contained.
// We then rotate the collider, and check again // We then rotate the collider, and check again
// Gets repeated for every possible rotation with a min-distance per axis of 2 deg // Gets repeated for every possible rotation with a min-distance per axis of 2 deg
TEST_METHOD(Points_Outside) TEST_CASE(__FILE__"/Points_Outside", "[TrapazoidalPrismCollider][Collider]")
{ {
// Setup // Setup
// Define known-inside points // Define known-inside points
std::array<Vector3d, 14> knownOutsides = { std::array<Vector3d, 14> knownOutsides = {
@ -136,7 +136,7 @@ namespace Colliders
// Exercise // Exercise
// Now check that these points are inside for all these possible angles // Now check that these points are inside for all these possible angles
#ifndef _DEBUG #ifndef _DEBUG
constexpr double stepSize = 2; constexpr double stepSize = 40;
#else #else
constexpr double stepSize = 32; constexpr double stepSize = 32;
#endif #endif
@ -157,10 +157,8 @@ namespace Colliders
// Verify // Verify
// Verify that all are inside // Verify that all are inside
for (const Vector3d& v : knownOutsides) for (const Vector3d& v : knownOutsides)
Assert::IsFalse(tpc.Contains(v)); REQUIRE_FALSE(tpc.Contains(v));
} }
return; return;
}
};
} }