Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencmath_test.cpp
Go to the documentation of this file.
00001 #define _STLP_DO_IMPORT_CSTD_FUNCTIONS 00002 00003 #include <limits> 00004 #include <cmath> 00005 //We also test math functions imported from stdlib.h or 00006 //defined in cstdlib 00007 #include <cstdlib> 00008 00009 #include "math_aux.h" 00010 #include "cppunit/cppunit_proxy.h" 00011 00012 //This test purpose is to check the right import of math.h C symbols 00013 //into the std namespace so we do not use the using namespace std 00014 //specification 00015 00016 // 00017 // TestCase class 00018 // 00019 class CMathTest : public CPPUNIT_NS::TestCase 00020 { 00021 CPPUNIT_TEST_SUITE(CMathTest); 00022 #if defined (STLPORT) && !defined (_STLP_USE_NAMESPACES) 00023 CPPUNIT_IGNORE; 00024 #endif 00025 CPPUNIT_TEST(import_checks); 00026 CPPUNIT_TEST_SUITE_END(); 00027 00028 protected: 00029 void import_checks(); 00030 }; 00031 00032 CPPUNIT_TEST_SUITE_REGISTRATION(CMathTest); 00033 00034 // 00035 // tests implementation 00036 // 00037 void CMathTest::import_checks() 00038 { 00039 #if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) 00040 int int_val = -1; 00041 long long_val = -1l; 00042 float float_val = -1.0f; 00043 double double_val = -1.0; 00044 # if !defined (_STLP_NO_LONG_DOUBLE) 00045 long double long_double_val = -1.0l; 00046 # endif 00047 00048 CPPUNIT_CHECK( are_equals(std::abs(int_val), -int_val) ); 00049 CPPUNIT_CHECK( are_equals(std::abs(long_val), -long_val) ); 00050 CPPUNIT_CHECK( are_equals(std::labs(long_val), -long_val) ); 00051 CPPUNIT_CHECK( are_equals(std::abs(float_val), -float_val) ); 00052 CPPUNIT_CHECK( are_equals(std::abs(double_val), -double_val) ); 00053 # if !defined (_STLP_NO_LONG_DOUBLE) 00054 CPPUNIT_CHECK( are_equals(std::abs(long_double_val), -long_double_val) ); 00055 # endif 00056 00057 CPPUNIT_CHECK( are_equals(std::fabs(float_val), -float_val) ); 00058 CPPUNIT_CHECK( are_equals(std::fabs(double_val), -double_val) ); 00059 # if !defined (_STLP_NO_LONG_DOUBLE) 00060 CPPUNIT_CHECK( are_equals(std::fabs(long_double_val), -long_double_val) ); 00061 # endif 00062 00063 std::div_t div_res = std::div(3, 2); 00064 CPPUNIT_CHECK( div_res.quot == 1 ); 00065 CPPUNIT_CHECK( div_res.rem == 1 ); 00066 std::ldiv_t ldiv_res = std::ldiv(3l, 2l); 00067 CPPUNIT_CHECK( ldiv_res.quot == 1l ); 00068 CPPUNIT_CHECK( ldiv_res.rem == 1l ); 00069 ldiv_res = std::div(3l, 2l); 00070 CPPUNIT_CHECK( ldiv_res.quot == 1l ); 00071 CPPUNIT_CHECK( ldiv_res.rem == 1l ); 00072 00073 std::srand(2); 00074 int rand_val = std::rand(); 00075 CPPUNIT_CHECK( rand_val >= 0 && rand_val <= RAND_MAX ); 00076 00077 CPPUNIT_CHECK( are_equals(std::floor(1.5), 1.0) ); 00078 CPPUNIT_CHECK( are_equals(std::ceil(1.5), 2.0) ); 00079 CPPUNIT_CHECK( are_equals(std::fmod(1.5, 1.0), 0.5) ); 00080 CPPUNIT_CHECK( are_equals(std::sqrt(4.0), 2.0) ); 00081 CPPUNIT_CHECK( are_equals(std::pow(2.0, 2), 4.0) ); 00082 /* 00083 * Uncomment the following to check that it generates an ambiguous call 00084 * as there is no Standard pow(int, int) function only pow(double, int), 00085 * pow(float, int) and some others... 00086 * If it do not generate a compile time error it should at least give 00087 * the good result. 00088 */ 00089 //CPPUNIT_CHECK( are_equals(std::pow(10, -2), 0.01) ); 00090 CPPUNIT_CHECK( are_equals(std::pow(10.0, -2), 0.01) ); 00091 CPPUNIT_CHECK( are_equals(std::exp(0.0), 1.0) ); 00092 CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0)), 1.0) ); 00093 CPPUNIT_CHECK( are_equals(std::log10(100.0), 2.0) ); 00094 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) 00095 CPPUNIT_CHECK( are_equals(std::modf(100.5, &double_val), 0.5) ); 00096 CPPUNIT_CHECK( are_equals(double_val, 100.0) ); 00097 # endif 00098 double_val = std::frexp(8.0, &int_val); 00099 CPPUNIT_CHECK( are_equals(double_val * std::pow(2.0, int_val), 8.0) ); 00100 CPPUNIT_CHECK( are_equals(std::ldexp(1.0, 2), 4.0) ); 00101 CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0)), 1.0) ); 00102 CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0)), 1.0) ); 00103 CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0)), 1.0) ); 00104 CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0, 1.0)), 1.0) ); 00105 CPPUNIT_CHECK( are_equals(std::cosh(0.0), 1.0) ); 00106 CPPUNIT_CHECK( are_equals(std::sinh(0.0), 0.0) ); 00107 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) 00108 CPPUNIT_CHECK( are_equals(std::tanh(0.0), 0.0) ); 00109 # endif 00110 00111 CPPUNIT_CHECK( are_equals(std::floor(1.5f), 1.0f) ); 00112 CPPUNIT_CHECK( are_equals(std::ceil(1.5f), 2.0f) ); 00113 CPPUNIT_CHECK( are_equals(std::fmod(1.5f, 1.0f), 0.5f) ); 00114 CPPUNIT_CHECK( are_equals(std::sqrt(4.0f), 2.0f) ); 00115 CPPUNIT_CHECK( are_equals(std::pow(2.0f, 2), 4.0f) ); 00116 CPPUNIT_CHECK( are_equals(std::exp(0.0f), 1.0f) ); 00117 CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0f)), 1.0f) ); 00118 CPPUNIT_CHECK( are_equals(std::log10(100.0f), 2.0f) ); 00119 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) 00120 CPPUNIT_CHECK( are_equals(std::modf(100.5f, &float_val), 0.5f) ); 00121 CPPUNIT_CHECK( are_equals(float_val, 100.0f) ); 00122 # endif 00123 float_val = std::frexp(8.0f, &int_val); 00124 CPPUNIT_CHECK( are_equals(float_val * std::pow(2.0f, int_val), 8.0f) ); 00125 CPPUNIT_CHECK( are_equals(std::ldexp(1.0f, 2), 4.0f) ); 00126 CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0f)), 1.0f) ); 00127 CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0f)), 1.0f) ); 00128 CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0f)), 1.0f) ); 00129 CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0f, 1.0f)), 1.0f) ); 00130 CPPUNIT_CHECK( are_equals(std::cosh(0.0f), 1.0f) ); 00131 CPPUNIT_CHECK( are_equals(std::sinh(0.0f), 0.0f) ); 00132 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) 00133 CPPUNIT_CHECK( are_equals(std::tanh(0.0f), 0.0f) ); 00134 # endif 00135 00136 # if !defined (_STLP_NO_LONG_DOUBLE) 00137 CPPUNIT_CHECK( are_equals(std::floor(1.5l), 1.0l) ); 00138 CPPUNIT_CHECK( are_equals(std::ceil(1.5l), 2.0l) ); 00139 CPPUNIT_CHECK( are_equals(std::fmod(1.5l, 1.0l), 0.5l) ); 00140 CPPUNIT_CHECK( are_equals(std::sqrt(4.0l), 2.0l) ); 00141 CPPUNIT_CHECK( are_equals(std::pow(2.0l, 2), 4.0l) ); 00142 CPPUNIT_CHECK( are_equals(std::exp(0.0l), 1.0l) ); 00143 CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0l)), 1.0l) ); 00144 CPPUNIT_CHECK( are_equals(std::log10(100.0l), 2.0l) ); 00145 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) 00146 CPPUNIT_CHECK( are_equals(std::modf(100.5l, &long_double_val), 0.5l) ); 00147 CPPUNIT_CHECK( are_equals(long_double_val, 100.0l) ); 00148 # endif 00149 long_double_val = std::frexp(8.0l, &int_val); 00150 CPPUNIT_CHECK( are_equals(long_double_val * std::pow(2.0l, int_val), 8.0l) ); 00151 CPPUNIT_CHECK( are_equals(std::ldexp(1.0l, 2), 4.0l) ); 00152 CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0l)), 1.0l) ); 00153 CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0l)), 1.0l) ); 00154 CPPUNIT_CHECK( are_equals(std::tan(0.0l), 0.0l) ); 00155 CPPUNIT_CHECK( are_equals(std::atan(0.0l), 0.0l) ); 00156 CPPUNIT_CHECK( are_equals(std::atan2(0.0l, 1.0l), 0.0l) ); 00157 CPPUNIT_CHECK( are_equals(std::cosh(0.0l), 1.0l) ); 00158 CPPUNIT_CHECK( are_equals(std::sinh(0.0l), 0.0l) ); 00159 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) 00160 CPPUNIT_CHECK( are_equals(std::tanh(0.0l), 0.0l) ); 00161 # endif 00162 # endif 00163 00164 CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0))), 2.0) ); 00165 CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0f))), 2.0f) ); 00166 # if !defined (_STLP_NO_LONG_DOUBLE) 00167 CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0l))), 2.0l) ); 00168 # endif 00169 #endif 00170 } Generated on Sun May 27 2012 04:35:19 for ReactOS by
1.7.6.1
|