@ -23,8 +23,12 @@ class FunctionsTest: public Corrade::TestSuite::Tester {
public :
FunctionsTest ( ) ;
void normalize ( ) ;
void denormalize ( ) ;
void normalizeUnsigned ( ) ;
void normalizeSigned ( ) ;
void denormalizeUnsigned ( ) ;
void denormalizeSigned ( ) ;
void renormalizeUnsinged ( ) ;
void renormalizeSinged ( ) ;
void clamp ( ) ;
void pow ( ) ;
void log ( ) ;
@ -32,62 +36,124 @@ class FunctionsTest: public Corrade::TestSuite::Tester {
} ;
FunctionsTest : : FunctionsTest ( ) {
addTests ( & FunctionsTest : : normalize ,
& FunctionsTest : : denormalize ,
addTests ( & FunctionsTest : : normalizeUnsigned ,
& FunctionsTest : : normalizeSigned ,
& FunctionsTest : : denormalizeUnsigned ,
& FunctionsTest : : denormalizeSigned ,
& FunctionsTest : : renormalizeUnsinged ,
& FunctionsTest : : renormalizeSinged ,
& FunctionsTest : : clamp ,
& FunctionsTest : : pow ,
& FunctionsTest : : log ,
& FunctionsTest : : log2 ) ;
}
void FunctionsTest : : normalize ( ) {
/* Range for signed and unsigned */
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int8_t > ( - 128 ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int8_t > ( 127 ) ) , 1.0f ) ;
void FunctionsTest : : normalizeUnsigned ( ) {
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint8_t > ( 0 ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint8_t > ( 255 ) ) , 1.0f ) ;
/* Between */
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( 16384 ) ) , 0.750011f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( - 16384 ) ) , 0.250004f ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : uint32_t > ( 0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : uint32_t > ( std : : numeric_limits < std : : uint32_t > : : max ( ) ) ) , 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < long double , std : : uint64_t > ( 0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < long double , std : : uint64_t > ( std : : numeric_limits < std : : uint64_t > : : max ( ) ) ) , 1.0 ) ;
/* Test overflow for large types */
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int32_t > ( std : : numeric_limits < std : : int32_t > : : min ( ) ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int32_t > ( std : : numeric_limits < std : : int32_t > : : max ( ) ) ) , 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint32_t > ( 0 ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint32_t > ( std : : numeric_limits < std : : uint32_t > : : max ( ) ) ) , 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint16_t > ( 0 ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint16_t > ( std : : numeric_limits < std : : uint16_t > : : max ( ) ) ) , 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : int64_t > ( std : : numeric_limits < std : : int64_t > : : min ( ) ) ) , 0.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : int64_t > ( std : : numeric_limits < std : : int64_t > : : max ( ) ) ) , 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : uint64_t > ( 0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : uint64_t > ( std : : numeric_limits < std : : uint64_t > : : max ( ) ) ) , 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint16_t > ( 8192 ) ) , 0.125002f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : uint16_t > ( 49152 ) ) , 0.750011f ) ;
}
void FunctionsTest : : denormalize ( ) {
/* Range for signed and unsigned */
CORRADE_COMPARE ( Math : : denormalize < std : : int8_t > ( 0.0f ) , - 128 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int8_t > ( 1.0f ) , 127 ) ;
void FunctionsTest : : normalizeSigned ( ) {
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int8_t > ( 127 ) ) , 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int8_t > ( 0 ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int8_t > ( - 128 ) ) , - 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( std : : numeric_limits < std : : int16_t > : : min ( ) ) ) , - 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( 0 ) ) , 0.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( std : : numeric_limits < std : : int16_t > : : max ( ) ) ) , 1.0f ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : int32_t > ( std : : numeric_limits < std : : int32_t > : : min ( ) ) ) , - 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : int32_t > ( 0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < double , std : : int32_t > ( std : : numeric_limits < std : : int32_t > : : max ( ) ) ) , 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < long double , std : : int64_t > ( std : : numeric_limits < std : : int64_t > : : min ( ) ) ) , - 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < long double , std : : int64_t > ( 0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < long double , std : : int64_t > ( std : : numeric_limits < std : : int64_t > : : max ( ) ) ) , 1.0 ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( 16384 ) ) , 0.500015f ) ;
CORRADE_COMPARE ( ( Math : : normalize < float , std : : int16_t > ( - 16384 ) ) , - 0.500015f ) ;
}
void FunctionsTest : : denormalizeUnsigned ( ) {
CORRADE_COMPARE ( Math : : denormalize < std : : uint8_t > ( 0.0f ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint8_t > ( 1.0f ) , 255 ) ;
/* Between */
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( 0.33f ) , - 11141 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( 0.66f ) , 10485 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint16_t > ( 0.0f ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint16_t > ( 1.0f ) , std : : numeric_limits < std : : uint16_t > : : max ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint32_t > ( 0.0 ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint32_t > ( 1.0 ) , std : : numeric_limits < std : : uint32_t > : : max ( ) ) ;
/* Test overflow for large types */
CORRADE_COMPARE ( Math : : denormalize < std : : int32_t > ( 0.0f ) , std : : numeric_limits < std : : int32_t > : : min ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint32_t > ( 0.0f ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int64_t > ( 0.0 ) , std : : numeric_limits < std : : int64_t > : : min ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint64_t > ( 0.0 ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint64_t > ( 1.0 ) , std : : numeric_limits < std : : uint64_t > : : max ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint16_t > ( 0.33f ) , 21626 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint16_t > ( 0.66f ) , 43253 ) ;
}
void FunctionsTest : : denormalizeSigned ( ) {
CORRADE_COMPARE ( Math : : denormalize < std : : int8_t > ( - 1.0f ) , - 127 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int8_t > ( 0.0f ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int8_t > ( 1.0f ) , 127 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( - 1.0f ) , std : : numeric_limits < std : : int16_t > : : min ( ) + 1 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( 0.0f ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( 1.0f ) , std : : numeric_limits < std : : int16_t > : : max ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int32_t > ( - 1.0 ) , std : : numeric_limits < std : : int32_t > : : min ( ) + 1 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int32_t > ( 0.0 ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int32_t > ( 1.0 ) , std : : numeric_limits < std : : int32_t > : : max ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : uint32_t > ( 1.0 ) , std : : numeric_limits < std : : uint32_t > : : max ( ) ) ;
// {
// CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well");
// 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());
// }
CORRADE_COMPARE ( Math : : denormalize < std : : int64_t > ( - 1.0 l ) , std : : numeric_limits < std : : int64_t > : : min ( ) + 1 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int64_t > ( 0.0 l ) , 0 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int64_t > ( 1.0 l ) , std : : numeric_limits < std : : int64_t > : : max ( ) ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( - 0.33f ) , - 10813 ) ;
CORRADE_COMPARE ( Math : : denormalize < std : : int16_t > ( 0.66f ) , 21626 ) ;
}
void FunctionsTest : : renormalizeUnsinged ( ) {
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : uint8_t > ( 0.0f ) ) , 0.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : uint8_t > ( 1.0f ) ) , 1.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : uint16_t > ( 0.0f ) ) , 0.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : uint16_t > ( 1.0f ) ) , 1.0f ) ;
CORRADE_COMPARE ( Math : : normalize < double > ( Math : : denormalize < std : : uint32_t > ( 0.0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( Math : : normalize < double > ( Math : : denormalize < std : : uint32_t > ( 1.0 ) ) , 1.0 ) ;
CORRADE_COMPARE ( Math : : normalize < long double > ( Math : : denormalize < std : : uint64_t > ( 0.0 l ) ) , 0.0 l ) ;
CORRADE_COMPARE ( Math : : normalize < long double > ( Math : : denormalize < std : : uint64_t > ( 1.0 l ) ) , 1.0 l ) ;
}
void FunctionsTest : : renormalizeSinged ( ) {
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : int8_t > ( - 1.0f ) ) , - 1.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : int8_t > ( 0.0f ) ) , 0.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : int8_t > ( 1.0f ) ) , 1.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : int16_t > ( - 1.0f ) ) , - 1.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : int16_t > ( 0.0f ) ) , 0.0f ) ;
CORRADE_COMPARE ( Math : : normalize < float > ( Math : : denormalize < std : : int16_t > ( 1.0f ) ) , 1.0f ) ;
CORRADE_COMPARE ( Math : : normalize < double > ( Math : : denormalize < std : : int32_t > ( - 1.0 ) ) , - 1.0 ) ;
CORRADE_COMPARE ( Math : : normalize < double > ( Math : : denormalize < std : : int32_t > ( 0.0 ) ) , 0.0 ) ;
CORRADE_COMPARE ( Math : : normalize < double > ( Math : : denormalize < std : : int32_t > ( 1.0 ) ) , 1.0 ) ;
CORRADE_COMPARE ( Math : : normalize < long double > ( Math : : denormalize < std : : int64_t > ( - 1.0 l ) ) , - 1.0 l ) ;
CORRADE_COMPARE ( Math : : normalize < long double > ( Math : : denormalize < std : : int64_t > ( 0.0 l ) ) , 0.0 l ) ;
CORRADE_COMPARE ( Math : : normalize < long double > ( Math : : denormalize < std : : int64_t > ( 1.0 l ) ) , 1.0 l ) ;
}
void FunctionsTest : : clamp ( ) {