From 282f3d5644c0e2a9e99512800682d31413ca39d0 Mon Sep 17 00:00:00 2001 From: sariug Date: Wed, 8 Apr 2020 22:49:40 +0200 Subject: [PATCH] add repeated tests, use better macros! --- src/Magnum/Math/Test/RandomTest.cpp | 73 +++++------------------------ 1 file changed, 13 insertions(+), 60 deletions(-) diff --git a/src/Magnum/Math/Test/RandomTest.cpp b/src/Magnum/Math/Test/RandomTest.cpp index 6265c80ac..e7364a84e 100644 --- a/src/Magnum/Math/Test/RandomTest.cpp +++ b/src/Magnum/Math/Test/RandomTest.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "Magnum/Math/Random.h" @@ -17,12 +18,9 @@ struct RandomTest : Corrade::TestSuite::Tester { explicit RandomTest(); - void unsignedScalar(); void signedScalar(); void unitVector2(); void unitVector3(); - void pointInACircle(); - void pointInASphere(); void randomRotation(); }; @@ -32,77 +30,32 @@ typedef Math::Constants Constants; RandomTest::RandomTest() { - addTests({&RandomTest::unsignedScalar, - &RandomTest::signedScalar, - &RandomTest::unitVector2, - &RandomTest::unitVector3, - &RandomTest::pointInACircle, - &RandomTest::pointInASphere, - &RandomTest::randomRotation}); -} - -// void RandomTest::construct() { -// constexpr Matrix4x4 a = {Vector4(3.0f, 5.0f, 8.0f, -3.0f), -// Vector4(4.5f, 4.0f, 7.0f, 2.0f), -// Vector4(1.0f, 2.0f, 3.0f, -1.0f), -// Vector4(7.9f, -1.0f, 8.0f, -1.5f)}; -// CORRADE_COMPARE(a, Matrix4x4(Vector4(3.0f, 5.0f, 8.0f, -3.0f), -// Vector4(4.5f, 4.0f, 7.0f, 2.0f), -// Vector4(1.0f, 2.0f, 3.0f, -1.0f), -// Vector4(7.9f, -1.0f, 8.0f, -1.5f))); - -// CORRADE_VERIFY((std::is_nothrow_constructible::value)); -// } -void RandomTest::unsignedScalar() -{ - for (std::size_t i = 0; i < 10; i++) - { - CORRADE_VERIFY(Math::Random::randomUnsignedScalar() < 1.000000001); - CORRADE_VERIFY(Math::Random::randomUnsignedScalar() > -.000000001); - } + Corrade::TestSuite::Tester::addRepeatedTests( + {&RandomTest::signedScalar, + &RandomTest::unitVector2, + &RandomTest::unitVector3, + &RandomTest::randomRotation}, + /*repeat number*/200); } void RandomTest::signedScalar() { - for (std::size_t i = 0; i < 10; i++) - { - CORRADE_VERIFY(Math::Random::randomUnsignedScalar() < 1.000000001); - CORRADE_VERIFY(Math::Random::randomUnsignedScalar() > -1.000000001); - } + CORRADE_COMPARE_AS(Math::Random::randomSignedScalar(), 1.0f, Corrade::TestSuite::Compare::LessOrEqual); + CORRADE_COMPARE_AS(Math::Random::randomSignedScalar(), -1.0f, Corrade::TestSuite::Compare::GreaterOrEqual); } void RandomTest::unitVector2() { - for (std::size_t i = 0; i < 10; i++) - { - CORRADE_COMPARE((Math::Random::randomUnitVector2()).length(),1.0f); - } + CORRADE_COMPARE((Math::Random::randomUnitVector2()).length(), 1.0f); } void RandomTest::unitVector3() { - for (std::size_t i = 0; i < 10; i++) - { - CORRADE_COMPARE((Math::Random::randomUnitVector3()).length(),1.0f); - } + CORRADE_COMPARE((Math::Random::randomUnitVector3()).length(), 1.0f); } -void RandomTest::pointInACircle(){ - for (std::size_t i = 0; i < 10; i++) - { - CORRADE_VERIFY((Math::Random::randomPointInACircle()).length()<1.0f); - } -} -void RandomTest::pointInASphere(){ - for (std::size_t i = 0; i < 10; i++) - { - CORRADE_VERIFY((Math::Random::randomPointInASphere()).length()<1.0f); - } -} -void RandomTest::randomRotation(){ - for (std::size_t i = 0; i < 10; i++) - { +void RandomTest::randomRotation() +{ CORRADE_COMPARE(Math::Random::randomRotation().length(), 1.0f); - } } } // namespace } // namespace Test