Browse Source

add repeated tests, use better macros!

pull/432/head
sariug 6 years ago
parent
commit
282f3d5644
  1. 73
      src/Magnum/Math/Test/RandomTest.cpp

73
src/Magnum/Math/Test/RandomTest.cpp

@ -1,4 +1,5 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Corrade/TestSuite/Compare/Numeric.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
#include "Magnum/Math/Random.h" #include "Magnum/Math/Random.h"
@ -17,12 +18,9 @@ struct RandomTest : Corrade::TestSuite::Tester
{ {
explicit RandomTest(); explicit RandomTest();
void unsignedScalar();
void signedScalar(); void signedScalar();
void unitVector2(); void unitVector2();
void unitVector3(); void unitVector3();
void pointInACircle();
void pointInASphere();
void randomRotation(); void randomRotation();
}; };
@ -32,77 +30,32 @@ typedef Math::Constants<Float> Constants;
RandomTest::RandomTest() RandomTest::RandomTest()
{ {
addTests({&RandomTest::unsignedScalar, Corrade::TestSuite::Tester::addRepeatedTests(
&RandomTest::signedScalar, {&RandomTest::signedScalar,
&RandomTest::unitVector2, &RandomTest::unitVector2,
&RandomTest::unitVector3, &RandomTest::unitVector3,
&RandomTest::pointInACircle, &RandomTest::randomRotation},
&RandomTest::pointInASphere, /*repeat number*/200);
&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<Matrix4x4, Vector4, Vector4, Vector4, Vector4>::value));
// }
void RandomTest::unsignedScalar()
{
for (std::size_t i = 0; i < 10; i++)
{
CORRADE_VERIFY(Math::Random::randomUnsignedScalar<Float>() < 1.000000001);
CORRADE_VERIFY(Math::Random::randomUnsignedScalar<Float>() > -.000000001);
}
} }
void RandomTest::signedScalar() void RandomTest::signedScalar()
{ {
for (std::size_t i = 0; i < 10; i++) CORRADE_COMPARE_AS(Math::Random::randomSignedScalar<Float>(), 1.0f, Corrade::TestSuite::Compare::LessOrEqual);
{ CORRADE_COMPARE_AS(Math::Random::randomSignedScalar<Float>(), -1.0f, Corrade::TestSuite::Compare::GreaterOrEqual);
CORRADE_VERIFY(Math::Random::randomUnsignedScalar<Float>() < 1.000000001);
CORRADE_VERIFY(Math::Random::randomUnsignedScalar<Float>() > -1.000000001);
}
} }
void RandomTest::unitVector2() 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() 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(){ void RandomTest::randomRotation()
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++)
{
CORRADE_COMPARE(Math::Random::randomRotation().length(), 1.0f); CORRADE_COMPARE(Math::Random::randomRotation().length(), 1.0f);
}
} }
} // namespace } // namespace
} // namespace Test } // namespace Test

Loading…
Cancel
Save