|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <cmath> |
| 4 | + |
| 5 | +namespace testing { |
| 6 | + |
| 7 | +#define ASSERT_THROW( condition) \ |
| 8 | +{ \ |
| 9 | + if( !( condition ) ) \ |
| 10 | + { \ |
| 11 | + throw std::runtime_error( std::string( "Assertion violated." ) \ |
| 12 | + + std::string( "\nIn:" ) \ |
| 13 | + + std::string( __FILE__ ) \ |
| 14 | + + std::string( ":" ) \ |
| 15 | + + std::to_string( __LINE__ ) \ |
| 16 | + + std::string( " in " ) \ |
| 17 | + + std::string( __FUNCTION__ ) \ |
| 18 | + ); \ |
| 19 | + } \ |
| 20 | +} |
| 21 | + |
| 22 | +#define ASSERT_EQUAL( x, y ) \ |
| 23 | +{ \ |
| 24 | + if( ( x ) != ( y ) ) \ |
| 25 | + { \ |
| 26 | + throw std::runtime_error( std::string( "Asserted equality violated." ) \ |
| 27 | + + std::string( "\nIn:" ) \ |
| 28 | + + std::string( __FILE__ ) \ |
| 29 | + + std::string( ":" ) \ |
| 30 | + + std::to_string( __LINE__ ) \ |
| 31 | + + std::string( " in " ) \ |
| 32 | + + std::string( __FUNCTION__ ) \ |
| 33 | + + std::string( ": " ) \ |
| 34 | + + std::to_string( ( x ) ) \ |
| 35 | + + std::string( " != " ) \ |
| 36 | + + std::to_string( ( y ) ) \ |
| 37 | + ); \ |
| 38 | + } \ |
| 39 | +} |
| 40 | + |
| 41 | +#define ASSERT_APPROX_EQUAL( x, y, eps ) \ |
| 42 | +{ \ |
| 43 | + if( abs(( x ) - ( y )) > eps ) \ |
| 44 | + { \ |
| 45 | + throw std::runtime_error( std::string( "Asserted approximate equality violated." ) \ |
| 46 | + + std::string( "\nIn:" ) \ |
| 47 | + + std::string( __FILE__ ) \ |
| 48 | + + std::string( ":" ) \ |
| 49 | + + std::to_string( __LINE__ ) \ |
| 50 | + + std::string( " in " ) \ |
| 51 | + + std::string( __FUNCTION__ ) \ |
| 52 | + + std::string( ": " ) \ |
| 53 | + + std::to_string( ( x ) ) \ |
| 54 | + + std::string( " != " ) \ |
| 55 | + + std::to_string( ( y ) ) \ |
| 56 | + ); \ |
| 57 | + } \ |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +#define ASSERT_MP_MINUSINFINITY( x ) \ |
| 62 | +{ \ |
| 63 | + if( ! MP_ISMINUSINFINITY(x) ) \ |
| 64 | + { \ |
| 65 | + throw std::runtime_error( std::string( "Asserted equality to minus infinity violated." ) \ |
| 66 | + + std::string( "\nIn:" ) \ |
| 67 | + + std::string( __FILE__ ) \ |
| 68 | + + std::string( ":" ) \ |
| 69 | + + std::to_string( __LINE__ ) \ |
| 70 | + + std::string( " in " ) \ |
| 71 | + + std::string( __FUNCTION__ ) \ |
| 72 | + + std::string( ": " ) \ |
| 73 | + + std::to_string( ( x ) ) \ |
| 74 | + + std::string( " != -inf" ) \ |
| 75 | + ); \ |
| 76 | + } \ |
| 77 | +} |
| 78 | + |
| 79 | +class Test { |
| 80 | + |
| 81 | +public: |
| 82 | + virtual void SetUp() = 0; |
| 83 | + virtual void TearDown() = 0; |
| 84 | + virtual void Run() = 0; |
| 85 | +}; |
| 86 | + |
| 87 | +} // namespace testing |
0 commit comments