| 60 | { |
| 61 | template<typename F, typename T> |
| 62 | void testSignedScaled() |
| 63 | { |
| 64 | typedef ScaledDataConversion< F, T > Func; |
| 65 | |
| 66 | Func f; |
| 67 | CompoundDataConversion< Func, typename Func::InverseType > f_fi( f, f.inverse() ); |
| 68 | |
| 69 | unsigned seed = 42; |
| 70 | boost::mt19937 generator( static_cast<boost::mt19937::result_type>( seed ) ); |
| 71 | |
| 72 | /// Create a random number generator within this range |
| 73 | boost::uniform_real<> uni_dist( std::numeric_limits<F>::min(), std::numeric_limits<F>::max() ); |
| 74 | boost::variate_generator<boost::mt19937&, boost::uniform_real<> > uni(generator, uni_dist); |
| 75 | |
| 76 | const int numTests = 100; |
| 77 | for ( int t = 0; t < numTests; t++) |
| 78 | { |
| 79 | F i = static_cast<F>( uni() ); |
| 80 | |
| 81 | /// Verify that f(f'(i)) ~ i |
| 82 | BOOST_CHECK_CLOSE( double( f_fi(i) ), double( i ), 1.e-4 ); |
| 83 | } |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | struct DataConversionTestSuite : public boost::unit_test::test_suite |