Skip to content

Commit

Permalink
add Vector{2,3} tests to CE split test
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Oct 11, 2022
1 parent 3cbeba1 commit 4f70b0d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Magnum/Math/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ corrade_add_test(MathVector2Test Vector2Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathVector3Test Vector3Test.cpp LIBRARIES MagnumMathTestLib)
corrade_add_test(MathVector4Test Vector4Test.cpp LIBRARIES MagnumMathTestLib)

foreach(_test VectorTest Vector4Test)
foreach(_test VectorTest Vector2Test Vector3Test Vector4Test)
corrade_add_test(Cpp14Math${_test} ${_test}.cpp LIBRARIES MagnumMathTestLib)
set_target_properties(Cpp14Math${_test} PROPERTIES CORRADE_CXX_STANDARD 14)
target_compile_definitions(Cpp14Math${_test} PRIVATE TESTING_CONSTEXPR CORRADE_GRACEFUL_ASSERT)
Expand Down
34 changes: 29 additions & 5 deletions src/Magnum/Math/Test/Vector2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "Magnum/Math/StrictWeakOrdering.h"
#include "Magnum/Math/Swizzle.h"

#include "Cpp14VectorTest.h"

struct Vec2 {
float x, y;
};
Expand All @@ -57,6 +59,7 @@ namespace Test { namespace {
struct Vector2Test: Corrade::TestSuite::Tester {
explicit Vector2Test();

#ifndef SKIP_TESTING
void construct();
void constructDefault();
void constructNoInit();
Expand All @@ -76,14 +79,24 @@ struct Vector2Test: Corrade::TestSuite::Tester {

void swizzleType();
void debug();
#else
void skipTesting();
#endif
};

typedef Math::Vector3<Int> Vector3i;
typedef Math::Vector2<Float> Vector2;
typedef Math::Vector2<Int> Vector2i;

Vector2Test::Vector2Test() {
addTests({&Vector2Test::construct,
#ifndef TESTING_CONSTEXPR
setTestName("MathVector2Test");
#else
setTestName("Cpp14MathVector2Test");
#endif
addTests({
#ifndef SKIP_TESTING
&Vector2Test::construct,
&Vector2Test::constructDefault,
&Vector2Test::constructNoInit,
&Vector2Test::constructOneValue,
Expand All @@ -101,9 +114,15 @@ Vector2Test::Vector2Test() {
&Vector2Test::strictWeakOrdering,

&Vector2Test::swizzleType,
&Vector2Test::debug});
&Vector2Test::debug
#else
&Vector2Test::skipTesting
#endif
});
}

#ifndef SKIP_TESTING

void Vector2Test::construct() {
constexpr Vector2 a = {1.5f, 2.5f};
CORRADE_COMPARE(a, (Vector<2, Float>(1.5f, 2.5f)));
Expand Down Expand Up @@ -197,7 +216,7 @@ void Vector2Test::convert() {
}

void Vector2Test::access() {
MAGNUM_CONSTEXPR14 Vector2 vec(1.0f, -2.0f);
CE Vector2 vec(1.0f, -2.0f);
CORRADE_COMPARE(vec.x(), 1.0f);
CORRADE_COMPARE(vec.y(), -2.0f);

Expand All @@ -209,8 +228,8 @@ void Vector2Test::access() {
}

void Vector2Test::cross() {
MAGNUM_CONSTEXPR14 Vector2i a(1, -1);
MAGNUM_CONSTEXPR14 Vector2i b(4, 3);
CE Vector2i a(1, -1);
CE Vector2i b(4, 3);

CORRADE_COMPARE(Math::cross(a, b), 7);
CORRADE_COMPARE(Math::cross<Int>({a, 0}, {b, 0}), Vector3i(0, 0, Math::cross(a, b)));
Expand Down Expand Up @@ -268,6 +287,11 @@ void Vector2Test::debug() {
Debug(&o) << Vector2(0.5f, 15.0f);
CORRADE_COMPARE(o.str(), "Vector(0.5, 15)\n");
}
#else
void Vector2Test::skipTesting() {
CORRADE_SKIP("Relaxed constexpr not supported by the compiler.");
}
#endif

}}}}

Expand Down
37 changes: 29 additions & 8 deletions src/Magnum/Math/Test/Vector3Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
DEALINGS IN THE SOFTWARE.
*/

#include "Cpp14VectorTest.h"

#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
Expand Down Expand Up @@ -57,6 +59,7 @@ namespace Test { namespace {
struct Vector3Test: Corrade::TestSuite::Tester {
explicit Vector3Test();

#ifndef SKIP_TESTING
void construct();
void constructDefault();
void constructNoInit();
Expand All @@ -76,14 +79,24 @@ struct Vector3Test: Corrade::TestSuite::Tester {

void swizzleType();
void debug();
#else
void skipTesting();
#endif
};

typedef Math::Vector3<Float> Vector3;
typedef Math::Vector3<Int> Vector3i;
typedef Math::Vector2<Float> Vector2;

Vector3Test::Vector3Test() {
addTests({&Vector3Test::construct,
#ifndef TESTING_CONSTEXPR
setTestName("MathVector3Test");
#else
setTestName("Cpp14MathVector3Test");
#endif
addTests({
#ifndef SKIP_TESTING
&Vector3Test::construct,
&Vector3Test::constructDefault,
&Vector3Test::constructNoInit,
&Vector3Test::constructOneValue,
Expand All @@ -101,9 +114,13 @@ Vector3Test::Vector3Test() {
&Vector3Test::strictWeakOrdering,

&Vector3Test::swizzleType,
&Vector3Test::debug});
&Vector3Test::debug
#else
&Vector3Test::skipTesting
#endif
});
}

#ifndef SKIP_TESTING
void Vector3Test::construct() {
constexpr Vector3 a = {1.0f, 2.5f, -3.0f};
CORRADE_COMPARE(a, (Vector<3, Float>(1.0f, 2.5f, -3.0f)));
Expand Down Expand Up @@ -206,7 +223,7 @@ void Vector3Test::convert() {
}

void Vector3Test::access() {
MAGNUM_CONSTEXPR14 Vector3 vec(1.0f, -2.0f, 5.0f);
CE Vector3 vec(1.0f, -2.0f, 5.0f);
CORRADE_COMPARE(vec.x(), 1.0f);
CORRADE_COMPARE(vec.r(), 1.0f);
CORRADE_COMPARE(vec.y(), -2.0f);
Expand All @@ -230,8 +247,8 @@ void Vector3Test::access() {
}

void Vector3Test::cross() {
MAGNUM_CONSTEXPR14 Vector3i a(1, -1, 1);
MAGNUM_CONSTEXPR14 Vector3i b(4, 3, 7);
CE Vector3i a(1, -1, 1);
CE Vector3i b(4, 3, 7);

CORRADE_COMPARE(Math::cross(a, b), Vector3i(-10, -3, 7));
}
Expand All @@ -255,7 +272,7 @@ void Vector3Test::scales() {
}

void Vector3Test::twoComponent() {
MAGNUM_CONSTEXPR14 Vector3 a(1.0f, 2.0f, 3.0f);
CE Vector3 a(1.0f, 2.0f, 3.0f);
CORRADE_COMPARE(a.xy(), Vector2(1.0f, 2.0f));

constexpr Vector3 b(1.0f, 2.0f, 3.0f);
Expand Down Expand Up @@ -292,7 +309,11 @@ void Vector3Test::debug() {
Debug(&o) << Vector3(0.5f, 15.0f, 1.0f);
CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n");
}

#else
void Vector3Test::skipTesting() {
CORRADE_SKIP("Relaxed constexpr not supported by the compiler.");
}
#endif
}}}}

CORRADE_TEST_MAIN(Magnum::Math::Test::Vector3Test)

0 comments on commit 4f70b0d

Please sign in to comment.