From bac5ccd8e611ff6056e0a69765fd622196af4925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 31 Aug 2016 19:24:20 +0200 Subject: [PATCH] Math: improve Angle test to be consistent with the rest. --- src/Magnum/Math/Test/AngleTest.cpp | 62 +++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/src/Magnum/Math/Test/AngleTest.cpp b/src/Magnum/Math/Test/AngleTest.cpp index f430e9475..64a8877a5 100644 --- a/src/Magnum/Math/Test/AngleTest.cpp +++ b/src/Magnum/Math/Test/AngleTest.cpp @@ -35,7 +35,11 @@ struct AngleTest: Corrade::TestSuite::Tester { explicit AngleTest(); void construct(); + void constructDefault(); void constructNoInit(); + void constructConversion(); + void constructCopy(); + void literals(); void conversion(); @@ -52,7 +56,11 @@ typedef Math::Rad Radd; AngleTest::AngleTest() { addTests({&AngleTest::construct, + &AngleTest::constructDefault, &AngleTest::constructNoInit, + &AngleTest::constructConversion, + &AngleTest::constructCopy, + &AngleTest::literals, &AngleTest::conversion, @@ -63,7 +71,17 @@ AngleTest::AngleTest() { } void AngleTest::construct() { - /* Default constructor */ + constexpr Deg b(25.0); + CORRADE_COMPARE(Float(b), 25.0f); + constexpr Radd n(3.14); + CORRADE_COMPARE(Double(n), 3.14); + + /* Implicit conversion is not allowed */ + CORRADE_VERIFY(!(std::is_convertible::value)); + CORRADE_VERIFY(!(std::is_convertible::value)); +} + +void AngleTest::constructDefault() { constexpr Deg m1; constexpr Deg m2{ZeroInit}; CORRADE_COMPARE(Float(m1), 0.0f); @@ -72,24 +90,6 @@ void AngleTest::construct() { constexpr Radd a2{ZeroInit}; CORRADE_COMPARE(Double(a1), 0.0); CORRADE_COMPARE(Double(a2), 0.0); - - /* Value constructor */ - constexpr Deg b(25.0); - CORRADE_COMPARE(Float(b), 25.0f); - constexpr Radd n(3.14); - CORRADE_COMPARE(Double(n), 3.14); - - /* Copy constructor */ - constexpr Deg c(b); - CORRADE_COMPARE(c, b); - constexpr Radd o(n); - CORRADE_COMPARE(o, n); - - /* Conversion operator */ - constexpr Rad p(n); - CORRADE_COMPARE(Float(p), 3.14f); - constexpr Degd d(b); - CORRADE_COMPARE(Double(d), 25.0); } void AngleTest::constructNoInit() { @@ -101,6 +101,30 @@ void AngleTest::constructNoInit() { CORRADE_COMPARE(Float(b), 3.14f); } +void AngleTest::constructConversion() { + constexpr Deg a(25.0); + constexpr Radd b(3.14); + + constexpr Rad c(b); + CORRADE_COMPARE(Float(c), 3.14f); + constexpr Degd d(a); + CORRADE_COMPARE(Double(d), 25.0); + + /* Implicit conversion is not allowed */ + CORRADE_VERIFY(!(std::is_convertible::value)); + CORRADE_VERIFY(!(std::is_convertible::value)); +} + +void AngleTest::constructCopy() { + constexpr Deg a(25.0); + constexpr Radd b(3.14); + + constexpr Deg c(a); + CORRADE_COMPARE(c, a); + constexpr Radd d(b); + CORRADE_COMPARE(d, b); +} + void AngleTest::literals() { using namespace Literals;