|
|
|
|
@ -17,12 +17,16 @@
|
|
|
|
|
|
|
|
|
|
#include "Math.h" |
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest) |
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Math { namespace Test { |
|
|
|
|
|
|
|
|
|
MathTest::MathTest() { |
|
|
|
|
addTests(&MathTest::degrad, |
|
|
|
|
&MathTest::normalize, |
|
|
|
|
&MathTest::denormalize, |
|
|
|
|
&MathTest::pow, |
|
|
|
|
&MathTest::log); |
|
|
|
|
} |
|
|
|
|
@ -33,6 +37,52 @@ void MathTest::degrad() {
|
|
|
|
|
CORRADE_COMPARE(rad(Constants<double>::pi()/2), Constants<double>::pi()/2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MathTest::normalize() { |
|
|
|
|
/* Range for signed and unsigned */ |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, char>(-128)), 0.0f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, char>(127)), 1.0f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, unsigned char>(0)), 0.0f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, unsigned char>(255)), 1.0f); |
|
|
|
|
|
|
|
|
|
/* Between */ |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, short>(16384)), 0.750011f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, short>(-16384)), 0.250004f); |
|
|
|
|
|
|
|
|
|
/* Test overflow for large types */ |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, int>(numeric_limits<int>::min())), 0.0f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, int>(numeric_limits<int>::max())), 1.0f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, unsigned int>(0)), 0.0f); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<float, unsigned int>(numeric_limits<unsigned int>::max())), 1.0f); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE((Math::normalize<double, long long>(numeric_limits<long long>::min())), 0.0); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<double, long long>(numeric_limits<long long>::max())), 1.0); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<double, unsigned long long>(0)), 0.0); |
|
|
|
|
CORRADE_COMPARE((Math::normalize<double, unsigned long long>(numeric_limits<unsigned long long>::max())), 1.0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MathTest::denormalize() { |
|
|
|
|
/* Range for signed and unsigned */ |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<char>(0.0f), -128); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<char>(1.0f), 127); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<unsigned char>(0.0f), 0); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<unsigned char>(1.0f), 255); |
|
|
|
|
|
|
|
|
|
/* Between */ |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<short>(0.33f), -11142); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<short>(0.66f), 10484); |
|
|
|
|
|
|
|
|
|
/* Test overflow for large types */ |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<int>(0.0f), numeric_limits<int>::min()); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<unsigned int>(0.0f), 0); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<long long>(0.0), numeric_limits<long long>::min()); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<unsigned long long>(0.0), 0); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Math::denormalize<int>(1.0), numeric_limits<int>::max()); |
|
|
|
|
CORRADE_COMPARE(Math::denormalize<unsigned int>(1.0), numeric_limits<unsigned int>::max()); |
|
|
|
|
CORRADE_COMPARE((Math::denormalize<long long, long double>(1.0)), numeric_limits<long long>::max()); |
|
|
|
|
CORRADE_COMPARE((Math::denormalize<unsigned long long, long double>(1.0)), numeric_limits<unsigned long long>::max()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MathTest::pow() { |
|
|
|
|
CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul); |
|
|
|
|
CORRADE_COMPARE(Math::pow<0>(3ul), 1ul); |
|
|
|
|
|