From 7b140db3ed7107945cb5dd6cdd518b650037da3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Mar 2013 18:29:21 +0100 Subject: [PATCH] Properly test swizzle() constexpr. Removed constExpressions() test case and merged it to others, reducing duplicate code. --- src/Math/Test/SwizzleTest.cpp | 28 ++++++++------------ src/Test/SwizzleTest.cpp | 48 ++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/Math/Test/SwizzleTest.cpp b/src/Math/Test/SwizzleTest.cpp index cb7596beb..5f01b4e62 100644 --- a/src/Math/Test/SwizzleTest.cpp +++ b/src/Math/Test/SwizzleTest.cpp @@ -35,7 +35,6 @@ class SwizzleTest: public Corrade::TestSuite::Tester { void components(); void constants(); void sizes(); - void constExpressions(); }; typedef Vector<4, Int> Vector4i; @@ -43,33 +42,28 @@ typedef Vector<4, Int> Vector4i; SwizzleTest::SwizzleTest() { addTests({&SwizzleTest::components, &SwizzleTest::constants, - &SwizzleTest::sizes, - &SwizzleTest::constExpressions}); + &SwizzleTest::sizes}); } void SwizzleTest::components() { - CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); + constexpr auto a = swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7)); + CORRADE_COMPARE(a, Vector4i(5, 2, 7, 4)); } void SwizzleTest::constants() { - CORRADE_COMPARE((swizzle<'1', 'w', '0', 'y'>(Vector4i(2, 4, 5, 7))), Vector4i(1, 7, 0, 4)); + constexpr auto a = swizzle<'1', 'w', '0', 'y'>(Vector4i(2, 4, 5, 7)); + CORRADE_COMPARE(a, Vector4i(1, 7, 0, 4)); } void SwizzleTest::sizes() { - CORRADE_COMPARE((swizzle<'y', 'x', 'x'>(Math::Vector<2, Int>(1, 2))), - (Math::Vector<3, Int>(2, 1, 1))); - CORRADE_COMPARE(swizzle<'z'>(Vector4i(1, 2, 3, 4)), - (Math::Vector<1, Int>(3))); - CORRADE_COMPARE((swizzle<'z', 'x', 'w', 'y', 'z', 'y', 'x'>(Vector4i(1, 2, 3, 4))), - (Math::Vector<7, Int>(3, 1, 4, 2, 3, 2, 1))); -} + constexpr auto a = swizzle<'y', 'x', 'x'>(Math::Vector<2, Int>(1, 2)); + CORRADE_COMPARE(a, (Math::Vector<3, Int>(2, 1, 1))); -void SwizzleTest::constExpressions() { - constexpr auto a = swizzle<'z', 'x', 'w', 'y'>(Vector4i(2, 4, 5, 7)); - CORRADE_COMPARE(a, Vector4i(5, 2, 7, 4)); + constexpr auto b = swizzle<'z'>(Vector4i(1, 2, 3, 4)); + CORRADE_COMPARE(b, (Math::Vector<1, Int>(3))); - constexpr auto b = swizzle<'1', 'w', '0', 'y'>(Vector4i(2, 4, 5, 7)); - CORRADE_COMPARE(b, Vector4i(1, 7, 0, 4)); + constexpr auto c = swizzle<'z', 'x', 'w', 'y', 'z', 'y', 'x'>(Vector4i(1, 2, 3, 4)); + CORRADE_COMPARE(c, (Math::Vector<7, Int>(3, 1, 4, 2, 3, 2, 1))); } }}} diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 75d281c44..e340c3fa8 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -44,27 +44,45 @@ SwizzleTest::SwizzleTest() { } void SwizzleTest::rgba() { - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g'>(Vector4i(2, 4, 5, 7))), Vector4i(5, 2, 7, 4)); + constexpr auto a = swizzle<'b', 'r', 'a', 'g'>(Vector4i(2, 4, 5, 7)); + CORRADE_COMPARE(a, Vector4i(5, 2, 7, 4)); } void SwizzleTest::type() { - Vector4i orig; - CORRADE_VERIFY((std::is_same(orig)), Vector2i>::value)); - CORRADE_VERIFY((std::is_same(orig)), Vector3i>::value)); - CORRADE_VERIFY((std::is_same(orig)), Vector4i>::value)); - - Color3 origColor3; - Color4 origColor4; - CORRADE_VERIFY((std::is_same(origColor3)), Color3>::value)); - CORRADE_VERIFY((std::is_same(origColor4)), Color3>::value)); - CORRADE_VERIFY((std::is_same(origColor3)), Color4>::value)); - CORRADE_VERIFY((std::is_same(origColor4)), Color4>::value)); + constexpr Vector4i orig; + constexpr Color3 origColor3; + constexpr Color4 origColor4; + + constexpr auto a = swizzle<'y', 'a'>(orig); + CORRADE_VERIFY((std::is_same::value)); + + constexpr auto b = swizzle<'y', 'z', 'a'>(orig); + CORRADE_VERIFY((std::is_same::value)); + + constexpr auto c = swizzle<'y', 'a', 'y', 'x'>(orig); + CORRADE_VERIFY((std::is_same::value)); + + constexpr auto d = swizzle<'y', 'z', 'r'>(origColor3); + CORRADE_VERIFY((std::is_same>::value)); + + constexpr auto e = swizzle<'y', 'z', 'a'>(origColor4); + CORRADE_VERIFY((std::is_same>::value)); + + constexpr auto f = swizzle<'y', 'z', 'y', 'x'>(origColor3); + CORRADE_VERIFY((std::is_same>::value)); + + constexpr auto g = swizzle<'y', 'a', 'y', 'x'>(origColor4); + CORRADE_VERIFY((std::is_same>::value)); } void SwizzleTest::defaultType() { - Vector4i orig(1, 2, 3, 4); - CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, Int>(3))); - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, Int>(3, 1, 4, 2, 3, 2, 1))); + constexpr Vector4i orig(1, 2, 3, 4); + + constexpr auto a = swizzle<'b'>(orig); + CORRADE_COMPARE(a, (Math::Vector<1, Int>(3))); + + constexpr auto b = swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig); + CORRADE_COMPARE(b, (Math::Vector<7, Int>(3, 1, 4, 2, 3, 2, 1))); } }}