From bb9b41057fd481c0b68f976bb441c327fbcc5eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 30 Aug 2018 17:39:42 +0200 Subject: [PATCH] Math: separate assertion tests into a dedicated test case. --- src/Magnum/Math/Test/QuaternionTest.cpp | 62 +++++++++++++++---------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/Magnum/Math/Test/QuaternionTest.cpp b/src/Magnum/Math/Test/QuaternionTest.cpp index 98e3149b2..f779d477d 100644 --- a/src/Magnum/Math/Test/QuaternionTest.cpp +++ b/src/Magnum/Math/Test/QuaternionTest.cpp @@ -88,7 +88,9 @@ struct QuaternionTest: Corrade::TestSuite::Tester { void angle(); void matrix(); void lerp(); + void lerpNotNormalized(); void slerp(); + void slerpNotNormalized(); void transformVector(); void transformVectorNormalized(); @@ -104,6 +106,8 @@ typedef Math::Quaternion Quaternion; typedef Math::Vector3 Vector3; typedef Math::Vector4 Vector4; +using namespace Math::Literals; + QuaternionTest::QuaternionTest() { addTests({&QuaternionTest::construct, &QuaternionTest::constructIdentity, @@ -141,7 +145,9 @@ QuaternionTest::QuaternionTest() { &QuaternionTest::angle, &QuaternionTest::matrix, &QuaternionTest::lerp, + &QuaternionTest::lerpNotNormalized, &QuaternionTest::slerp, + &QuaternionTest::slerpNotNormalized, &QuaternionTest::transformVector, &QuaternionTest::transformVectorNormalized, @@ -455,38 +461,32 @@ void QuaternionTest::matrix() { } void QuaternionTest::lerp() { - Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); - Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); - - std::ostringstream o; - Error redirectError{&o}; - - Math::lerp(a*3.0f, b, 0.35f); - CORRADE_COMPARE(o.str(), "Math::lerp(): quaternions must be normalized\n"); - - o.str({}); - Math::lerp(a, b*-3.0f, 0.35f); - CORRADE_COMPARE(o.str(), "Math::lerp(): quaternions must be normalized\n"); - + Quaternion a = Quaternion::rotation(15.0_degf, Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::rotation(23.0_degf, Vector3::xAxis()); Quaternion lerp = Math::lerp(a, b, 0.35f); + + CORRADE_VERIFY(lerp.isNormalized()); CORRADE_COMPARE(lerp, Quaternion({0.119127f, 0.049134f, 0.049134f}, 0.990445f)); } -void QuaternionTest::slerp() { - Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants::sqrt3())); - Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); +void QuaternionTest::lerpNotNormalized() { + std::ostringstream out; + Error redirectError{&out}; - std::ostringstream o; - Error redirectError{&o}; - - Math::slerp(a*3.0f, b, 0.35f); - CORRADE_COMPARE(o.str(), "Math::slerp(): quaternions must be normalized\n"); - - o.str({}); - Math::slerp(a, b*-3.0f, 0.35f); - CORRADE_COMPARE(o.str(), "Math::slerp(): quaternions must be normalized\n"); + Quaternion a; + Math::lerp(a*3.0f, a, 0.35f); + Math::lerp(a, a*-3.0f, 0.35f); + CORRADE_COMPARE(out.str(), + "Math::lerp(): quaternions must be normalized\n" + "Math::lerp(): quaternions must be normalized\n"); +} +void QuaternionTest::slerp() { + Quaternion a = Quaternion::rotation(15.0_degf, Vector3(1.0f/Constants::sqrt3())); + Quaternion b = Quaternion::rotation(23.0_degf, Vector3::xAxis()); Quaternion slerp = Math::slerp(a, b, 0.35f); + + CORRADE_VERIFY(slerp.isNormalized()); CORRADE_COMPARE(slerp, Quaternion({0.1191653f, 0.0491109f, 0.0491109f}, 0.9904423f)); /* Avoid division by zero */ @@ -494,6 +494,18 @@ void QuaternionTest::slerp() { CORRADE_COMPARE(Math::slerp(a, -a, 0.42f), a); } +void QuaternionTest::slerpNotNormalized() { + std::ostringstream out; + Error redirectError{&out}; + + Quaternion a; + Math::slerp(a*3.0f, a, 0.35f); + Math::slerp(a, a*-3.0f, 0.35f); + CORRADE_COMPARE(out.str(), + "Math::slerp(): quaternions must be normalized\n" + "Math::slerp(): quaternions must be normalized\n"); +} + void QuaternionTest::transformVector() { Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); Matrix4 m = Matrix4::rotationX(Deg(23.0f));