Tests: Update Catch2 to 3.x

This commit is contained in:
SirLynix
2022-08-01 18:05:33 +02:00
parent c6851d93c2
commit 481702c109
53 changed files with 230 additions and 179 deletions

View File

@@ -1,6 +1,7 @@
#include <Nazara/Math/Algorithm.hpp>
#include <Nazara/Math/Angle.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <limits>
TEST_CASE("Approach", "[MATH][ALGORITHM]")
@@ -61,7 +62,7 @@ TEST_CASE("DegreeToRadian", "[MATH][ALGORITHM]")
{
SECTION("Convert 45.f degree to radian")
{
REQUIRE(Nz::DegreeToRadian(45.f) == Approx(Nz::Pi<float> / 4.f));
REQUIRE(Nz::DegreeToRadian(45.f) == Catch::Approx(Nz::Pi<float> / 4.f));
}
}
@@ -323,7 +324,7 @@ TEST_CASE("RadianToDegree", "[MATH][ALGORITHM]")
{
SECTION("PI / 4 to degree")
{
REQUIRE(Nz::RadianToDegree(Nz::Pi<float> / 4.f) == Approx(45.f));
REQUIRE(Nz::RadianToDegree(Nz::Pi<float> / 4.f) == Catch::Approx(45.f));
}
}

View File

@@ -1,7 +1,8 @@
#include <Nazara/Math/Angle.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Angle", "[MATH][ANGLE]")
{
@@ -36,8 +37,8 @@ SCENARIO("Angle", "[MATH][ANGLE]")
{
THEN("It should be equal to 1 and 0")
{
CHECK(angle.GetSin() == Approx(1.f).margin(0.0001f));
CHECK(angle.GetCos() == Approx(0.f).margin(0.0001f));
CHECK(angle.GetSin() == Catch::Approx(1.f).margin(0.0001f));
CHECK(angle.GetCos() == Catch::Approx(0.f).margin(0.0001f));
}
AND_WHEN("We compute sin/cos at the same time")
{
@@ -45,8 +46,8 @@ SCENARIO("Angle", "[MATH][ANGLE]")
THEN("It should also be equal to 1 and 0")
{
CHECK(sincos.first == Approx(1.f).margin(0.0001f));
CHECK(sincos.second == Approx(0.f).margin(0.0001f));
CHECK(sincos.first == Catch::Approx(1.f).margin(0.0001f));
CHECK(sincos.second == Catch::Approx(0.f).margin(0.0001f));
}
}
}
@@ -135,8 +136,8 @@ SCENARIO("Angle", "[MATH][ANGLE]")
{
THEN("It should be equal to 0 and -1")
{
CHECK(angle.GetSin() == Approx(0.f).margin(0.0001f));
CHECK(angle.GetCos() == Approx(-1.f).margin(0.0001f));
CHECK(angle.GetSin() == Catch::Approx(0.f).margin(0.0001f));
CHECK(angle.GetCos() == Catch::Approx(-1.f).margin(0.0001f));
}
}
@@ -146,8 +147,8 @@ SCENARIO("Angle", "[MATH][ANGLE]")
THEN("It should also be equal to 0 and -1")
{
CHECK(sincos.first == Approx(0.f).margin(0.0001f));
CHECK(sincos.second == Approx(-1.f).margin(0.0001f));
CHECK(sincos.first == Catch::Approx(0.f).margin(0.0001f));
CHECK(sincos.second == Catch::Approx(-1.f).margin(0.0001f));
}
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/BoundingVolume.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
{

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Box.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Box", "[MATH][BOX]")
{
@@ -40,9 +41,9 @@ SCENARIO("Box", "[MATH][BOX]")
REQUIRE(firstCenterAndUnit.GetNegativeVertex(Nz::Vector3f::Unit()) == Nz::Vector3f::Zero());
REQUIRE(firstCenterAndUnit.GetPosition() == Nz::Vector3f::Zero());
REQUIRE(firstCenterAndUnit.GetPositiveVertex(Nz::Vector3f::Unit()) == Nz::Vector3f::Unit());
REQUIRE(firstCenterAndUnit.GetRadius() == Approx(std::sqrt(3.f * 0.5f * 0.5f)));
REQUIRE(firstCenterAndUnit.GetRadius() == Catch::Approx(std::sqrt(3.f * 0.5f * 0.5f)));
REQUIRE(firstCenterAndUnit.GetSquaredBoundingSphere() == Nz::Spheref(Nz::Vector3f::Unit() * 0.5f, 3.f * 0.5f * 0.5f));
REQUIRE(firstCenterAndUnit.GetSquaredRadius() == Approx(3.f * 0.5f * 0.5f));
REQUIRE(firstCenterAndUnit.GetSquaredRadius() == Catch::Approx(3.f * 0.5f * 0.5f));
}
}

View File

@@ -1,6 +1,7 @@
#include <Nazara/Math/Angle.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
{
@@ -88,19 +89,19 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
THEN("And then convert to euler angles, we have identity")
{
Nz::EulerAnglesf tmp = Nz::Quaternionf(euler45.ToQuaternion()).ToEulerAngles();
CHECK(tmp.pitch.ToDegrees() == Approx(0.f));
CHECK(tmp.yaw.ToDegrees() == Approx(22.5f));
CHECK(tmp.roll.ToDegrees() == Approx(22.5f));
CHECK(tmp.pitch.ToDegrees() == Catch::Approx(0.f));
CHECK(tmp.yaw.ToDegrees() == Catch::Approx(22.5f));
CHECK(tmp.roll.ToDegrees() == Catch::Approx(22.5f));
tmp = Nz::Quaternionf(euler90.ToQuaternion()).ToEulerAngles();
CHECK(tmp.pitch.ToDegrees() == Approx(90.f));
CHECK(tmp.yaw.ToDegrees() == Approx(90.f));
CHECK(tmp.roll.ToDegrees() == Approx(0.f));
CHECK(tmp.pitch.ToDegrees() == Catch::Approx(90.f));
CHECK(tmp.yaw.ToDegrees() == Catch::Approx(90.f));
CHECK(tmp.roll.ToDegrees() == Catch::Approx(0.f));
tmp = Nz::Quaternionf(euler30.ToQuaternion()).ToEulerAngles();
CHECK(tmp.pitch.ToDegrees() == Approx(30.f));
CHECK(tmp.yaw.ToDegrees() == Approx(0.f).margin(0.0001f));
CHECK(tmp.roll.ToDegrees() == Approx(30.f));
CHECK(tmp.pitch.ToDegrees() == Catch::Approx(30.f));
CHECK(tmp.yaw.ToDegrees() == Catch::Approx(0.f).margin(0.0001f));
CHECK(tmp.roll.ToDegrees() == Catch::Approx(30.f));
}
}
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Frustum.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Frustum", "[MATH][FRUSTUM]")
{

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Matrix4.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <array>
@@ -67,8 +68,8 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
{
THEN("These results are expected")
{
CHECK(matrix1.GetDeterminant() == Approx(24.f));
CHECK(matrix2.GetDeterminant() == Approx(-1.f));
CHECK(matrix1.GetDeterminant() == Catch::Approx(24.f));
CHECK(matrix2.GetDeterminant() == Catch::Approx(-1.f));
}
}
@@ -83,8 +84,8 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
THEN("We get the identity")
{
Nz::Matrix4f tmp = matrix1 * invMatrix1;
CHECK(tmp.m32 == Approx(0.f).margin(0.0001f));
CHECK(tmp.m42 == Approx(0.f).margin(0.0001f));
CHECK(tmp.m32 == Catch::Approx(0.f).margin(0.0001f));
CHECK(tmp.m42 == Catch::Approx(0.f).margin(0.0001f));
tmp.m32 = 0.f;
tmp.m42 = 0.f;
CHECK(tmp == Nz::Matrix4f::Identity());
@@ -215,9 +216,9 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
{
identity.ApplyRotation(Nz::EulerAnglesf(Nz::DegreeAnglef(10.f), Nz::DegreeAnglef(20.f), Nz::DegreeAnglef(30.f)));
Nz::Vector3f retrievedScale = identity.GetScale();
CHECK(retrievedScale.x == Approx(scale.x));
CHECK(retrievedScale.y == Approx(scale.y));
CHECK(retrievedScale.z == Approx(scale.z));
CHECK(retrievedScale.x == Catch::Approx(scale.x));
CHECK(retrievedScale.y == Catch::Approx(scale.y));
CHECK(retrievedScale.z == Catch::Approx(scale.z));
}
}
}
@@ -233,7 +234,7 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
{
THEN("We expect those to be true")
{
CHECK(negativeDeterminant.GetDeterminant() == Approx(-1.f));
CHECK(negativeDeterminant.GetDeterminant() == Catch::Approx(-1.f));
CHECK(!negativeDeterminant.HasScale());
CHECK(negativeDeterminant.HasNegativeScale());
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/OrientedBox.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
{

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Plane.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Plane", "[MATH][PLANE]")
{
@@ -23,30 +24,30 @@ SCENARIO("Plane", "[MATH][PLANE]")
AND_THEN("They have the same distance from the same point")
{
Nz::Vector3f point(-2.f, 3.f, 1.f);
REQUIRE(firstPlane.Distance(point) == Approx(secondPlane.Distance(point)));
REQUIRE(firstPlane.Distance(-2.f, 3.f, 1.f) == Approx(0.1547f));
REQUIRE(firstPlane.Distance(point) == Catch::Approx(secondPlane.Distance(point)));
REQUIRE(firstPlane.Distance(-2.f, 3.f, 1.f) == Catch::Approx(0.1547f));
}
AND_THEN("Distance between Plane (0, 1, 0), distance 1 and point (0, 2, 0) should be 1")
{
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Approx(1.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Catch::Approx(1.f));
}
AND_THEN("Distance between Plane (0, 1, 0), distance 5 and point (0, 2, 0) should be -3")
{
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 5.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Approx(-3.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 5.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Catch::Approx(-3.f));
}
AND_THEN("Distance between Plane (0, 1, 0), distance 1000 and point (0, 500, 0) and (0, 1500, 0)")
{
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Approx(-500.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Approx(500.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Catch::Approx(-500.f));
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Catch::Approx(500.f));
}
AND_THEN("Distance between Plane (0, -1, 0), distance -1000 and point (0, 500, 0) and (0, 1500, 0)")
{
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Approx(500.f));
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Approx(-500.f));
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Catch::Approx(500.f));
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Catch::Approx(-500.f));
}
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Quaternion.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
@@ -15,7 +16,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
REQUIRE(firstQuaternion == secondQuaternion);
REQUIRE(firstQuaternion.ComputeW() == secondQuaternion.Normalize());
REQUIRE(firstQuaternion.Conjugate() == secondQuaternion.Inverse());
REQUIRE(firstQuaternion.DotProduct(secondQuaternion) == Approx(1.f));
REQUIRE(firstQuaternion.DotProduct(secondQuaternion) == Catch::Approx(1.f));
}
}
@@ -45,7 +46,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
REQUIRE(inverted == zero);
REQUIRE(normalized == zero);
REQUIRE(tmp == Approx(0.f));
REQUIRE(tmp == Catch::Approx(0.f));
}
}
}
@@ -63,11 +64,11 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
{
THEN("They are all equal to 1")
{
REQUIRE(w.Magnitude() == Approx(1.f));
REQUIRE(x.Magnitude() == Approx(1.f));
REQUIRE(y.Magnitude() == Approx(1.f));
REQUIRE(z.Magnitude() == Approx(1.f));
REQUIRE(xyzw.Magnitude() == Approx(1.f));
REQUIRE(w.Magnitude() == Catch::Approx(1.f));
REQUIRE(x.Magnitude() == Catch::Approx(1.f));
REQUIRE(y.Magnitude() == Catch::Approx(1.f));
REQUIRE(z.Magnitude() == Catch::Approx(1.f));
REQUIRE(xyzw.Magnitude() == Catch::Approx(1.f));
}
}
@@ -144,15 +145,15 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
THEN("The half of 10 and 30 is 20")
{
Nz::Quaternionf slerpx10x30a = Nz::Quaternionf::Slerp(x10, x30a, 0.5f);
REQUIRE(slerpx10x30a.w == Approx(x20.w));
REQUIRE(slerpx10x30a.x == Approx(x20.x));
REQUIRE(slerpx10x30a.y == Approx(x20.y));
REQUIRE(slerpx10x30a.z == Approx(x20.z));
REQUIRE(slerpx10x30a.w == Catch::Approx(x20.w));
REQUIRE(slerpx10x30a.x == Catch::Approx(x20.x));
REQUIRE(slerpx10x30a.y == Catch::Approx(x20.y));
REQUIRE(slerpx10x30a.z == Catch::Approx(x20.z));
Nz::Quaternionf slerpx10x30b = Nz::Quaternionf::Slerp(x10, x30b, 0.5f);
REQUIRE(slerpx10x30b.w == Approx(x20.w));
REQUIRE(slerpx10x30b.x == Approx(x20.x));
REQUIRE(slerpx10x30b.y == Approx(x20.y));
REQUIRE(slerpx10x30b.z == Approx(x20.z));
REQUIRE(slerpx10x30b.w == Catch::Approx(x20.w));
REQUIRE(slerpx10x30b.x == Catch::Approx(x20.x));
REQUIRE(slerpx10x30b.y == Catch::Approx(x20.y));
REQUIRE(slerpx10x30b.z == Catch::Approx(x20.z));
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 0.f) == x10);
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 1.f) == x30a);
}
@@ -164,10 +165,10 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
Nz::Quaternionf quaternionC = Nz::Quaternionf::Slerp(quaterionA, quaterionB, 0.5f);
Nz::Quaternionf unitZ225(Nz::DegreeAnglef(22.5f), Nz::Vector3f::UnitZ());
REQUIRE(quaternionC.w == Approx(unitZ225.w));
REQUIRE(quaternionC.x == Approx(unitZ225.x));
REQUIRE(quaternionC.y == Approx(unitZ225.y));
REQUIRE(quaternionC.z == Approx(unitZ225.z));
REQUIRE(quaternionC.w == Catch::Approx(unitZ225.w));
REQUIRE(quaternionC.x == Catch::Approx(unitZ225.x));
REQUIRE(quaternionC.y == Catch::Approx(unitZ225.y));
REQUIRE(quaternionC.z == Catch::Approx(unitZ225.z));
}
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Ray.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Ray", "[MATH][RAY]")
{
@@ -21,7 +22,7 @@ SCENARIO("Ray", "[MATH][RAY]")
{
THEN("The point that is multiple on the Nz::Ray, is at multiple")
{
REQUIRE(ray.ClosestPoint(secondRay.GetPoint(1.f)) == Approx(1.f));
REQUIRE(ray.ClosestPoint(secondRay.GetPoint(1.f)) == Catch::Approx(1.f));
}
}
@@ -90,7 +91,7 @@ SCENARIO("Ray", "[MATH][RAY]")
float tmpFurthest = -1.f;
Nz::BoundingVolumef infiniteVolume(Nz::Extend::Infinite);
CHECK(ray.Intersect(infiniteVolume, &tmpClosest, &tmpFurthest));
CHECK(tmpClosest == Approx(0.f));
CHECK(tmpClosest == Catch::Approx(0.f));
CHECK(tmpFurthest == std::numeric_limits<float>::infinity());
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Rect.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Rect", "[MATH][RECT]")
{

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Sphere.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
SCENARIO("Sphere", "[MATH][SPHERE]")
{
@@ -41,10 +42,10 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
{
THEN("These results are expected because we don't take into account the border")
{
CHECK(firstCenterAndUnit.Distance(Nz::Vector3f::UnitX() * 2.f) == Approx(1.f));
CHECK(firstCenterAndUnit.Distance(Nz::Vector3f::UnitX() * 2.f) == Catch::Approx(1.f));
Nz::Spheref tmp(Nz::Vector3f::UnitX(), 1.f);
CHECK(tmp.Distance(Nz::Vector3f::UnitX() * 4.f) == Approx(2.f));
CHECK(tmp.Distance(Nz::Vector3f::UnitX() * 4.f) == Catch::Approx(2.f));
}
}
@@ -79,12 +80,12 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
firstCenterAndUnit.ExtendTo(point);
REQUIRE(firstCenterAndUnit.radius == Approx(2.f));
REQUIRE(firstCenterAndUnit.radius == Catch::Approx(2.f));
THEN("Sphere must contain it and distance should be good")
{
CHECK(firstCenterAndUnit.Contains(point));
CHECK(firstCenterAndUnit.Distance(point) == Approx(0.f));
CHECK(firstCenterAndUnit.Distance(point) == Catch::Approx(0.f));
}
}

View File

@@ -1,4 +1,5 @@
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector4.hpp>
@@ -25,8 +26,8 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
THEN("These are perpendicular")
{
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f));
REQUIRE(firstUnit.AngleBetween(tmp) == Nz::DegreeAnglef(90.f));
Nz::Vector2f negativeUnitX = -Nz::Vector2f::UnitX();
REQUIRE(negativeUnitX.AngleBetween(negativeUnitX + Nz::Vector2f(0, 0.0000001f)) == Nz::DegreeAnglef(360.f));
@@ -40,12 +41,12 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
THEN("These are expected")
{
REQUIRE(firstUnit.Distance(tmp2) == Approx(2.f * std::sqrt(2.f)));
REQUIRE(firstUnit.Distance(tmp) == Approx(5.f));
REQUIRE(firstUnit.SquaredDistance(tmp) == Approx(25.f));
REQUIRE(firstUnit.Distance(tmp2) == Catch::Approx(2.f * std::sqrt(2.f)));
REQUIRE(firstUnit.Distance(tmp) == Catch::Approx(5.f));
REQUIRE(firstUnit.SquaredDistance(tmp) == Catch::Approx(25.f));
REQUIRE(firstUnit.GetSquaredLength() == Approx(2.f));
REQUIRE(firstUnit.GetLength() == Approx(std::sqrt(2.f)));
REQUIRE(firstUnit.GetSquaredLength() == Catch::Approx(2.f));
REQUIRE(firstUnit.GetLength() == Catch::Approx(std::sqrt(2.f)));
}
}
@@ -56,14 +57,14 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
{
Nz::Vector2f normalized = firstUnit.GetNormal(&ratio);
REQUIRE(normalized == (Nz::Vector2f::Unit() / std::sqrt(2.f)));
REQUIRE(ratio == Approx(std::sqrt(2.f)));
REQUIRE(ratio == Catch::Approx(std::sqrt(2.f)));
}
THEN("For null vector")
{
Nz::Vector2f zero = Nz::Vector2f::Zero();
REQUIRE(zero.GetNormal(&ratio) == Nz::Vector2f::Zero());
REQUIRE(ratio == Approx(0.f));
REQUIRE(ratio == Catch::Approx(0.f));
}
}

View File

@@ -1,4 +1,5 @@
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
@@ -24,8 +25,8 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
THEN("These results are expected")
{
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f));
REQUIRE(firstUnit.AngleBetween(tmp) == Nz::DegreeAnglef(90.f));
REQUIRE(firstUnit.AngleBetween(-firstUnit) == Nz::DegreeAnglef(180.f));
}
@@ -46,11 +47,11 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
THEN("These are expected")
{
REQUIRE(firstUnit.Distance(tmp) == Approx(11.f));
REQUIRE(firstUnit.SquaredDistance(tmp) == Approx(121.f));
REQUIRE(firstUnit.Distance(tmp) == Catch::Approx(11.f));
REQUIRE(firstUnit.SquaredDistance(tmp) == Catch::Approx(121.f));
REQUIRE(firstUnit.GetSquaredLength() == Approx(3.f));
REQUIRE(firstUnit.GetLength() == Approx(std::sqrt(3.f)));
REQUIRE(firstUnit.GetSquaredLength() == Catch::Approx(3.f));
REQUIRE(firstUnit.GetLength() == Catch::Approx(std::sqrt(3.f)));
}
}
@@ -61,14 +62,14 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
{
Nz::Vector3f normalized = firstUnit.GetNormal(&ratio);
REQUIRE(normalized == (Nz::Vector3f::Unit() / std::sqrt(3.f)));
REQUIRE(ratio == Approx(std::sqrt(3.f)));
REQUIRE(ratio == Catch::Approx(std::sqrt(3.f)));
}
THEN("For null vector")
{
Nz::Vector3f zero = Nz::Vector3f::Zero();
REQUIRE(zero.GetNormal(&ratio) == Nz::Vector3f::Zero());
REQUIRE(ratio == Approx(0.f));
REQUIRE(ratio == Catch::Approx(0.f));
}
}

View File

@@ -1,5 +1,6 @@
#include <Nazara/Math/Vector4.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <Nazara/Math/Vector3.hpp>
@@ -24,8 +25,8 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
THEN("These results are expected")
{
REQUIRE(firstUnit.AbsDotProduct(tmp) == Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Approx(0.f));
REQUIRE(firstUnit.AbsDotProduct(tmp) == Catch::Approx(2.f));
REQUIRE(firstUnit.DotProduct(tmp) == Catch::Approx(0.f));
}
}