diff -r e20de85af2ee -r ce057bb09d0b genericopenlibs/cppstdlib/stl/test/unit/cmath_test.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/genericopenlibs/cppstdlib/stl/test/unit/cmath_test.cpp Fri Jun 04 16:20:51 2010 +0100 @@ -0,0 +1,1239 @@ +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#define _STLP_DO_IMPORT_CSTD_FUNCTIONS + +#include +#include +#include +//We also test math functions imported from stdlib.h or +//defined in cstdlib +#include + +#include "math_aux.h" +#include "cppunit/cppunit_proxy.h" + +//This test purpose is to check the right import of math.h C symbols +//into the std namespace so we do not use the using namespace std +//specification + +// +// TestCase class +// +class CMathTest : public CPPUNIT_NS::TestCase +{ + CPPUNIT_TEST_SUITE(CMathTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST(complex_double_cov1); + CPPUNIT_TEST(complex_double_cov2); + CPPUNIT_TEST(complex_double_cov3); + CPPUNIT_TEST(complex_double_cov4); + CPPUNIT_TEST(complex_float_cov1); + CPPUNIT_TEST(complex_float_cov2); + CPPUNIT_TEST(complex_float_cov3); + CPPUNIT_TEST(complex_float_cov4); + CPPUNIT_TEST(complex_longdouble_cov1); + CPPUNIT_TEST(complex_longdouble_cov2); + CPPUNIT_TEST(complex_longdouble_cov3); + CPPUNIT_TEST(complex_longdouble_cov4); + CPPUNIT_TEST(complex_trigonometric_cov); + CPPUNIT_TEST(complex_cmath_cov); + CPPUNIT_TEST(complex_templates_cov1); + CPPUNIT_TEST(complex_templates_cov2); + CPPUNIT_TEST(complex_constructors_cov1); + CPPUNIT_TEST(complex_constructors_cov2); + CPPUNIT_TEST_SUITE_END(); + + protected: + void test(); + void complex_double_cov1(); + void complex_double_cov2(); + void complex_double_cov3(); + void complex_double_cov4(); + void complex_float_cov1(); + void complex_float_cov2(); + void complex_float_cov3(); + void complex_float_cov4(); + void complex_longdouble_cov1(); + void complex_longdouble_cov2(); + void complex_longdouble_cov3(); + void complex_longdouble_cov4(); + void complex_trigonometric_cov(); + void complex_cmath_cov(); + void complex_templates_cov1(); + void complex_templates_cov2(); + void complex_constructors_cov1(); + void complex_constructors_cov2(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(CMathTest); + +// +// tests implementation +// +void CMathTest::test() +{ + int int_val = -1; + long long_val = -1l; + float float_val = -1.0f; + double double_val = -1.0; +#if !defined (_STLP_NO_LONG_DOUBLE) + long double long_double_val = -1.0l; +#endif + + CPPUNIT_CHECK( are_equals(std::abs(int_val), -int_val) ); + CPPUNIT_CHECK( are_equals(std::abs(long_val), -long_val) ); + CPPUNIT_CHECK( are_equals(std::labs(long_val), -long_val) ); + CPPUNIT_CHECK( are_equals(std::abs(float_val), -float_val) ); + CPPUNIT_CHECK( are_equals(std::abs(double_val), -double_val) ); +#if !defined (_STLP_NO_LONG_DOUBLE) + CPPUNIT_CHECK( are_equals(std::abs(long_double_val), -long_double_val) ); +#endif + + CPPUNIT_CHECK( are_equals(std::fabs(float_val), -float_val) ); + CPPUNIT_CHECK( are_equals(std::fabs(double_val), -double_val) ); +#if !defined (_STLP_NO_LONG_DOUBLE) + CPPUNIT_CHECK( are_equals(std::fabs(long_double_val), -long_double_val) ); +#endif + + std::div_t div_res = std::div(3, 2); + CPPUNIT_CHECK( div_res.quot == 1 ); + CPPUNIT_CHECK( div_res.rem == 1 ); + std::ldiv_t ldiv_res = std::ldiv(3l, 2l); + CPPUNIT_CHECK( ldiv_res.quot == 1l ); + CPPUNIT_CHECK( ldiv_res.rem == 1l ); + ldiv_res = std::div(3l, 2l); + CPPUNIT_CHECK( ldiv_res.quot == 1l ); + CPPUNIT_CHECK( ldiv_res.rem == 1l ); + + std::srand(2); + int rand_val = std::rand(); + CPPUNIT_CHECK( rand_val >= 0 && rand_val <= RAND_MAX ); + + CPPUNIT_CHECK( are_equals(std::floor(1.5), 1.0) ); + CPPUNIT_CHECK( are_equals(std::ceil(1.5), 2.0) ); + CPPUNIT_CHECK( are_equals(std::fmod(1.5, 1.0), 0.5) ); + CPPUNIT_CHECK( are_equals(std::sqrt(4.0), 2.0) ); + CPPUNIT_CHECK( are_equals(std::pow(2.0, 2), 4.0) ); + /* + * Uncomment the following to check that it generates an ambiguous call + * as there is no Standard pow(int, int) function only pow(double, int), + * pow(float, int) and some others... + * If it do not generate a compile time error it should at least give + * the good result. + */ + //CPPUNIT_CHECK( are_equals(std::pow(10, -2), 0.01) ); + CPPUNIT_CHECK( are_equals(std::pow(10.0, -2), 0.01) ); + CPPUNIT_CHECK( are_equals(std::exp(0.0), 1.0) ); + CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0)), 1.0) ); + CPPUNIT_CHECK( are_equals(std::log10(100.0), 2.0) ); +#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) + CPPUNIT_CHECK( are_equals(std::modf(100.5, &double_val), 0.5) ); + CPPUNIT_CHECK( are_equals(double_val, 100.0) ); +#endif + double_val = std::frexp(8.0, &int_val); + CPPUNIT_CHECK( are_equals(double_val * std::pow(2.0, int_val), 8.0) ); + CPPUNIT_CHECK( are_equals(std::ldexp(1.0, 2), 4.0) ); + CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0)), 1.0) ); + CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0)), 1.0) ); + CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0)), 1.0) ); + CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0, 1.0)), 1.0) ); + CPPUNIT_CHECK( are_equals(std::cosh(0.0), 1.0) ); + CPPUNIT_CHECK( are_equals(std::sinh(0.0), 0.0) ); +#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) + CPPUNIT_CHECK( are_equals(std::tanh(0.0), 0.0) ); +#endif + + CPPUNIT_CHECK( are_equals(std::floor(1.5f), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::ceil(1.5f), 2.0f) ); + CPPUNIT_CHECK( are_equals(std::fmod(1.5f, 1.0f), 0.5f) ); + CPPUNIT_CHECK( are_equals(std::sqrt(4.0f), 2.0f) ); + CPPUNIT_CHECK( are_equals(std::pow(2.0f, 2), 4.0f) ); + CPPUNIT_CHECK( are_equals(std::exp(0.0f), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0f)), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::log10(100.0f), 2.0f) ); +#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) + CPPUNIT_CHECK( are_equals(std::modf(100.5f, &float_val), 0.5f) ); + CPPUNIT_CHECK( are_equals(float_val, 100.0f) ); +#endif + float_val = std::frexp(8.0f, &int_val); + CPPUNIT_CHECK( are_equals(float_val * std::pow(2.0f, int_val), 8.0f) ); + CPPUNIT_CHECK( are_equals(std::ldexp(1.0f, 2), 4.0f) ); + CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0f)), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0f)), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0f)), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0f, 1.0f)), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::cosh(0.0f), 1.0f) ); + CPPUNIT_CHECK( are_equals(std::sinh(0.0f), 0.0f) ); +#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) + CPPUNIT_CHECK( are_equals(std::tanh(0.0f), 0.0f) ); +#endif + +#if !defined (_STLP_NO_LONG_DOUBLE) + CPPUNIT_CHECK( are_equals(std::floor(1.5l), 1.0l) ); + CPPUNIT_CHECK( are_equals(std::ceil(1.5l), 2.0l) ); + CPPUNIT_CHECK( are_equals(std::fmod(1.5l, 1.0l), 0.5l) ); + CPPUNIT_CHECK( are_equals(std::sqrt(4.0l), 2.0l) ); + CPPUNIT_CHECK( are_equals(std::pow(2.0l, 2), 4.0l) ); + CPPUNIT_CHECK( are_equals(std::exp(0.0l), 1.0l) ); + CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0l)), 1.0l) ); + CPPUNIT_CHECK( are_equals(std::log10(100.0l), 2.0l) ); +# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) + CPPUNIT_CHECK( are_equals(std::modf(100.5l, &long_double_val), 0.5l) ); + CPPUNIT_CHECK( are_equals(long_double_val, 100.0l) ); +# endif + long_double_val = std::frexp(8.0l, &int_val); + CPPUNIT_CHECK( are_equals(long_double_val * std::pow(2.0l, int_val), 8.0l) ); + CPPUNIT_CHECK( are_equals(std::ldexp(1.0l, 2), 4.0l) ); + CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0l)), 1.0l) ); + CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0l)), 1.0l) ); + CPPUNIT_CHECK( are_equals(std::tan(0.0l), 0.0l) ); + CPPUNIT_CHECK( are_equals(std::atan(0.0l), 0.0l) ); + CPPUNIT_CHECK( are_equals(std::atan2(0.0l, 1.0l), 0.0l) ); + CPPUNIT_CHECK( are_equals(std::cosh(0.0l), 1.0l) ); + CPPUNIT_CHECK( are_equals(std::sinh(0.0l), 0.0l) ); +# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) + CPPUNIT_CHECK( are_equals(std::tanh(0.0l), 0.0l) ); +# endif +#endif + + CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0))), 2.0) ); + CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0f))), 2.0f) ); +#if !defined (_STLP_NO_LONG_DOUBLE) + CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0l))), 2.0l) ); +#endif +} +void CMathTest::complex_double_cov1() + { + using namespace std; + double pi = 3.14159265359; + // Test Case for abs,arg abd SQRT + { + complex c1( polar ( 5.0 ) ); + complex c2 ( polar ( 5.0 , pi / 6 ) ); + double absc1 = abs ( c1 ); + double argc1 = arg ( c1 ); + CPPUNIT_CHECK( absc1 == 5 ); + CPPUNIT_CHECK( argc1 == 0 ); + double normc2 = norm ( c2 ); + double sqrtnormc2 = sqrt ( normc2 ); + CPPUNIT_CHECK(sqrtnormc2 == 5); + } + // Test case for the real,imag and conj + { + complex c1 ( 4.0 , 3.0 ); + double dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 4); + double di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 3); + complex c2 = conj ( c1 ); + double dr2 = real ( c2 ); + CPPUNIT_CHECK(dr2 == 4); + double di2 = imag ( c2 ); + CPPUNIT_CHECK(di2 == -3); + } + // test case for the operator "=" , the 3 templates + { + complex cl1 ( polar (3.0 , pi / 6 ) ); + complex cr1a ( polar (2.0 , pi /3 ) ); + complex cr1b ( polar (2.0 , pi / 3 ) ); + CPPUNIT_CHECK(cl1 != cr1a); + CPPUNIT_CHECK(cr1b == cr1a); + + double cl3a =3; + double cl3b =5; + complex cr3a ( 3 , 4 ); + complex cr3b ( 5 ,0 ); + CPPUNIT_CHECK(cl3a != cr3a); + CPPUNIT_CHECK(cl3b == cr3b); + + complex cl2a ( 3 , 4 ); + complex cl2b ( 5 ,0 ); + int cr2a =3; + CPPUNIT_CHECK(cl2a != cr2a); + } +} +void CMathTest::complex_double_cov2() + { + using namespace std; + double pi = 3.14159265359; + // test case for the operator "*" , the 3 templates + { + complex cl1 ( polar (3.0 , pi / 6 ) ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cl2 ( polar ( 3.0 , pi / 6 ) ); + double cr2 =5; + complex cs2 = cl2 * cr2; + double cl3 = 5; + complex cr3 ( polar (3.0 , pi / 6 ) ); + complex cs3 = cl3 * cr3; + + CPPUNIT_CHECK(cs1 == cs2); + CPPUNIT_CHECK(cs3 == cs2); + } + // test case for the operator "+" , the 3 templates + { + complex cl1 ( polar (3.0 , pi / 6 ) ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cl2 ( polar ( 3.0 , pi / 6 ) ); + double cr2 =5; + complex cs2 = cl2 + cr2; + double cl3 = 5; + complex cr3 ( polar (3.0 , pi / 6 ) ); + complex cs3 = cl3 + cr3; + + complex cr4 ( 3.0 , 4.0 ); + complex cs4 = + cr4; + + CPPUNIT_CHECK(cs4 == cr4); + CPPUNIT_CHECK(cs1 == cs2); + CPPUNIT_CHECK(cs3 == cs2); + } + // test case for the operator "-" , the 3 templates + { + complex cl1 (3 , 4); + complex cr1 ( 2,3 ); + complex cs1 = cl1 - cr1; + complex cs11 ( 1,1 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (3 , 4); + double cr2 =5; + complex cs2 = cl2 - cr2; + complex cs22 (-2 , 4); + CPPUNIT_CHECK(cs2 == cs22); + + double cl3 = 5; + complex cr3 (3 , 4); + complex cs3 = cl3 - cr3; + complex cs33 (2 , -4); + CPPUNIT_CHECK(cs3 == cs33); + + complex cr4 ( 3 , 4 ); + complex cs4 = -cr4; + complex cs44 (-3 , -4); + CPPUNIT_CHECK(cs4 == cs44); + } + // test case for the operator "/" , the 3 templates + { + complex cl1 (4 , 4); + complex cr1 ( 2,2 ); + complex cs1 = cl1/cr1; + complex cs11 ( 2,0 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (4 , 4); + double cr2 =2; + complex cs2 = cl2/cr2; + complex cs22 (2 , 2); + CPPUNIT_CHECK(cs2 == cs22); + + double cl3 = 4; + complex cr3 (2 , 2); + complex cs3 = cl3/cr3; + complex cs33 (1 , -1); + CPPUNIT_CHECK(cs3 == cs33); + } +} + +void CMathTest::complex_double_cov3() + { + using namespace std; + double pi = 3.14159265359; + // test case for the operator "*=" , the 3 templates + { + complex cl1 ( polar (3.0 , pi / 6 ) ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cs11 (10,0); + complex cint1 ( 2,0 ); + complex csresult (20,0); + cl1 *= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + double val = 2; + cr1 *= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 *= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "+=" , the 3 templates + { + complex cl1 ( polar (3.0 , pi / 6 ) ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cs11 (7,0); + complex cint1 ( 2,0 ); + complex csresult (9,0); + cl1 += cr1; + CPPUNIT_CHECK(cs1 == cl1); + + double val = 2; + cr1 += val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 += cint1; + CPPUNIT_CHECK(csresult == cs11); + } +} + +void CMathTest::complex_double_cov4() + { + using namespace std; + double pi = 3.14159265359; + // test case for the operator "-=" , the 3 templates + { + complex cl1 ( polar (3.0 , pi / 6 ) ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 - cr1; + complex cs11 (3,0); + complex cint1 ( 2,0 ); + complex csresult (1,0); + cl1 -= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + double val = 2; + cr1 -= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 -= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "/=" , the 3 templates + { + complex cl1 ( 10,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1/cr1; + complex cs11 (1,0); + complex cint1 ( 1,0 ); + complex csresult (1,0); + cl1 /= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + double val = 5; + cr1 /= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 /= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "=" , the 3 templates + { + complex cl1 ( 3.0 , 4.0 ); + complex cr1 ( 2.0 , -1.0 ); + cl1 = cr1; + CPPUNIT_CHECK(cl1 == cr1); + complex cl2 ( -2 , 4 ); + double cr2 =5.0; + cl2 = cr2; + CPPUNIT_CHECK(cl2 == cr2); + complex cl3(3.0, 4.0); + cl2 = cl3; + CPPUNIT_CHECK(cl2 == cl3); + } +} + +void CMathTest::complex_float_cov1() + { + using namespace std; + // test case for the abs,arg and sqrt + { + complex c1( polar ( 5.0 ) ); + complex c2 ( 5,0 ); + float absc1 = abs ( c1 ); + float argc1 = arg ( c1 ); + CPPUNIT_CHECK( absc1 == 5 ); + CPPUNIT_CHECK( argc1 == 0 ); + float normc2 = norm ( c2 ); + float val = 25; + float sqrtnormc2 = sqrt ( normc2 ); + CPPUNIT_CHECK(normc2 == val); + CPPUNIT_CHECK(sqrtnormc2 == 5); + } + // test case for the real,imag and conj + { + complex c1 ( 4.0 , 3.0 ); + float dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 4); + float di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 3); + complex c2 = conj ( c1 ); + float dr2 = real ( c2 ); + CPPUNIT_CHECK(dr2 == 4); + float di2 = imag ( c2 ); + CPPUNIT_CHECK(di2 == -3); + } + // test case for the operator "=" , the 3 templates + { + complex cl1 ( 7,7 ); + complex cr1a ( 5,7 ); + complex cr1b ( 5,7 ); + CPPUNIT_CHECK(cl1 != cr1a); + CPPUNIT_CHECK(cr1b == cr1a); + + float cl3a =3; + float cl3b =5; + complex cr3a ( 3 , 4 ); + complex cr3b ( 5 ,0 ); + CPPUNIT_CHECK(cl3a != cr3a); + CPPUNIT_CHECK(cl3b == cr3b); + + complex cl2a ( 3 , 4 ); + complex cl2b ( 5 ,0 ); + int cr2a =3; + CPPUNIT_CHECK(cl2a != cr2a); + } + } +void CMathTest::complex_float_cov2() + { + using namespace std; + // test case for the operator "*" , the 3 templates + { + complex cl1 ( 7,5 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cl2 ( 7,5 ); + float cr2 =5; + complex cs2 = cl2 * cr2; + float cl3 = 5; + complex cr3 ( 7,5 ); + complex cs3 = cl3 * cr3; + + CPPUNIT_CHECK(cs1 == cs2); + CPPUNIT_CHECK(cs3 == cs2); + } + // test case for the operator "+" , the 3 templates + { + complex cl1 ( 7,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cl2 ( 7,0 ); + float cr2 =5; + complex cs2 = cl2 + cr2; + float cl3 = 5; + complex cr3 ( 7,0 ); + complex cs3 = cl3 + cr3; + + complex cr4 ( 3.0 , 4.0 ); + complex cs4 = + cr4; + + CPPUNIT_CHECK(cs4 == cr4); + CPPUNIT_CHECK(cs1 == cs2); + CPPUNIT_CHECK(cs3 == cs2); + } + // test case for the operator "-" , the 3 templates + { + complex cl1 (3 , 4); + complex cr1 ( 2,3 ); + complex cs1 = cl1 - cr1; + complex cs11 ( 1,1 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (3 , 4); + float cr2 =5; + complex cs2 = cl2 - cr2; + complex cs22 (-2 , 4); + CPPUNIT_CHECK(cs2 == cs22); + + float cl3 = 5; + complex cr3 (3 , 4); + complex cs3 = cl3 - cr3; + complex cs33 (2 , -4); + CPPUNIT_CHECK(cs3 == cs33); + + complex cr4 ( 3 , 4 ); + complex cs4 = -cr4; + complex cs44 (-3 , -4); + CPPUNIT_CHECK(cs4 == cs44); + } + // test case for the operator "/" , the 3 templates + { + complex cl1 (4 , 4); + complex cr1 ( 2,2 ); + complex cs1 = cl1/cr1; + complex cs11 ( 2,0 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (4 , 4); + float cr2 =2; + complex cs2 = cl2/cr2; + complex cs22 (2 , 2); + CPPUNIT_CHECK(cs2 == cs22); + + float cl3 = 4; + complex cr3 (2 , 2); + complex cs3 = cl3/cr3; + complex cs33 (1 , -1); + CPPUNIT_CHECK(cs3 == cs33); + } + } +void CMathTest::complex_float_cov3() + { + using namespace std; + // test case for the operator "*=" , the 3 templates + { + complex cl1 ( 7,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cs11 (10,0); + complex cint1 ( 2,0 ); + complex csresult (20,0); + cl1 *= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + float val = 2; + cr1 *= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 *= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "+=" , the 3 templates + { + complex cl1 ( 7,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cs11 (7,0); + complex cint1 ( 2,0 ); + complex csresult (9,0); + cl1 += cr1; + CPPUNIT_CHECK(cs1 == cl1); + + float val = 2; + cr1 += val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 += cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "-=" , the 3 templates + { + complex cl1 ( 7,7 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 - cr1; + complex cs11 (3,0); + complex cint1 ( 2,0 ); + complex csresult (1,0); + cl1 -= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + float val = 2; + cr1 -= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 -= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + } +void CMathTest::complex_float_cov4() + { + using namespace std; + // test case for the operator "/=" , the 3 templates + { + complex cl1 ( 10,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1/cr1; + complex cs11 (1,0); + complex cint1 ( 1,0 ); + complex csresult (1,0); + cl1 /= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + float val = 5; + cr1 /= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 /= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "=" , the 3 templates + { + complex cl1 ( 3.0 , 4.0 ); + complex cr1 ( 2.0 , -1.0 ); + cl1 = cr1; + CPPUNIT_CHECK(cl1 == cr1); + complex cl2 ( -2 , 4 ); + float cr2 =5.0; + cl2 = cr2; + CPPUNIT_CHECK(cl2 == cr2); + complex cl3(3.0, 4.0); + cl2 = cl3; + CPPUNIT_CHECK(cl2 == cl3); + } +} + +void CMathTest::complex_longdouble_cov1() + { + using namespace std; + // test case for the abs,arg and sqrt + { + complex c1( polar ( 5.0 ) ); + complex c2 ( 5,0 ); + long double absc1 = abs ( c1 ); + long double argc1 = arg ( c1 ); + CPPUNIT_CHECK( absc1 == 5 ); + CPPUNIT_CHECK( argc1 == 0 ); + long double normc2 = norm ( c2 ); + long double val = 25; + long double sqrtnormc2 = sqrt ( normc2 ); + CPPUNIT_CHECK(normc2 == val); + CPPUNIT_CHECK(sqrtnormc2 == 5); + } + // test case for the real,imag and conj + { + complex c1 ( 4.0 , 3.0 ); + long double dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 4); + long double di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 3); + complex c2 = conj ( c1 ); + long double dr2 = real ( c2 ); + CPPUNIT_CHECK(dr2 == 4); + long double di2 = imag ( c2 ); + CPPUNIT_CHECK(di2 == -3); + } + // test case for the operator "=" , the 3 templates + { + complex cl1 ( 7,7 ); + complex cr1a ( 5,7 ); + complex cr1b ( 5,7 ); + CPPUNIT_CHECK(cl1 != cr1a); + CPPUNIT_CHECK(cr1b == cr1a); + + long double cl3a =3; + long double cl3b =5; + complex cr3a ( 3 , 4 ); + complex cr3b ( 5 ,0 ); + CPPUNIT_CHECK(cl3a != cr3a); + CPPUNIT_CHECK(cl3b == cr3b); + + complex cl2a ( 3 , 4 ); + complex cl2b ( 5 ,0 ); + int cr2a =3; + CPPUNIT_CHECK(cl2a != cr2a); + } + } +void CMathTest::complex_longdouble_cov2() + { + using namespace std; + // test case for the operator "*" , the 3 templates + { + complex cl1 ( 7,5 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cl2 ( 7,5 ); + long double cr2 =5; + complex cs2 = cl2 * cr2; + long double cl3 = 5; + complex cr3 ( 7,5 ); + complex cs3 = cl3 * cr3; + + CPPUNIT_CHECK(cs1 == cs2); + CPPUNIT_CHECK(cs3 == cs2); + } + // test case for the operator "+" , the 3 templates + { + complex cl1 ( 7,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cl2 ( 7,0 ); + long double cr2 =5; + complex cs2 = cl2 + cr2; + long double cl3 = 5; + complex cr3 ( 7,0 ); + complex cs3 = cl3 + cr3; + + complex cr4 ( 3.0 , 4.0 ); + complex cs4 = + cr4; + + CPPUNIT_CHECK(cs4 == cr4); + CPPUNIT_CHECK(cs1 == cs2); + CPPUNIT_CHECK(cs3 == cs2); + } + // test case for the operator "-" , the 3 templates + { + complex cl1 (3 , 4); + complex cr1 ( 2,3 ); + complex cs1 = cl1 - cr1; + complex cs11 ( 1,1 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (3 , 4); + long double cr2 =5; + complex cs2 = cl2 - cr2; + complex cs22 (-2 , 4); + CPPUNIT_CHECK(cs2 == cs22); + + long double cl3 = 5; + complex cr3 (3 , 4); + complex cs3 = cl3 - cr3; + complex cs33 (2 , -4); + CPPUNIT_CHECK(cs3 == cs33); + + complex cr4 ( 3 , 4 ); + complex cs4 = -cr4; + complex cs44 (-3 , -4); + CPPUNIT_CHECK(cs4 == cs44); + } + // test case for the operator "/" , the 3 templates + { + complex cl1 (4 , 4); + complex cr1 ( 2,2 ); + complex cs1 = cl1/cr1; + complex cs11 ( 2,0 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (4 , 4); + long double cr2 =2; + complex cs2 = cl2/cr2; + complex cs22 (2 , 2); + CPPUNIT_CHECK(cs2 == cs22); + + long double cl3 = 4; + complex cr3 (2 , 2); + complex cs3 = cl3/cr3; + complex cs33 (1 , -1); + CPPUNIT_CHECK(cs3 == cs33); + } + } +void CMathTest::complex_longdouble_cov3() + { + using namespace std; + // test case for the operator "*=" , the 3 templates + { + complex cl1 ( 7,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cs11 (10,0); + complex cint1 ( 2,0 ); + complex csresult (20,0); + cl1 *= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + long double val = 2; + cr1 *= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 *= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "+=" , the 3 templates + { + complex cl1 ( 7,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cs11 (7,0); + complex cint1 ( 2,0 ); + complex csresult (9,0); + cl1 += cr1; + CPPUNIT_CHECK(cs1 == cl1); + + long double val = 2; + cr1 += val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 += cint1; + CPPUNIT_CHECK(csresult == cs11); + } + } +void CMathTest::complex_longdouble_cov4() + { + using namespace std; + // test case for the operator "-=" , the 3 templates + { + complex cl1 ( 7,7 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 - cr1; + complex cs11 (3,0); + complex cint1 ( 2,0 ); + complex csresult (1,0); + cl1 -= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + long double val = 2; + cr1 -= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 -= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "/=" , the 3 templates + { + complex cl1 ( 10,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1/cr1; + complex cs11 (1,0); + complex cint1 ( 1,0 ); + complex csresult (1,0); + cl1 /= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + long double val = 5; + cr1 /= val; + CPPUNIT_CHECK(cr1 == cs11); + cs11 /= cint1; + CPPUNIT_CHECK(csresult == cs11); + } + // test case for the operator "=" , the 3 templates + { + complex cl1 ( 3.0 , 4.0 ); + complex cr1 ( 2.0 , -1.0 ); + cl1 = cr1; + CPPUNIT_CHECK(cl1 == cr1); + complex cl2 ( -2 , 4 ); + long double cr2 =5.0; + cl2 = cr2; + CPPUNIT_CHECK(cl2 == cr2); + complex cl3(3.0, 4.0); + cl2 = cl3; + CPPUNIT_CHECK(cl2 == cl3); + } +} +void CMathTest::complex_trigonometric_cov() + { + using namespace std; + + complex c1 ( 5,0 ); + complex c2 ( 5,0 ); + complex c3 ( 5,0 ); + + complex cdresult; + complex cfresult; + complex cldresult; + + cdresult = cos ( c1 ); + cfresult = cos ( c2 ); + cldresult = cos ( c3 ); + + cdresult = cosh ( c1 ); + cfresult = cosh ( c2 ); + cldresult = cosh ( c3 ); + + cdresult = sin ( c1 ); + cfresult = sin ( c2 ); + cldresult = sin ( c3 ); + + cdresult = sinh ( c1 ); + cfresult = sinh ( c2 ); + cldresult = sinh ( c3 ); + + cdresult = tan ( c1 ); + cfresult = tan ( c2 ); + cldresult = tan ( c3 ); + + cdresult = tanh ( c1 ); + cfresult = tanh ( c2 ); + cldresult = tanh ( c3 ); + } + +void CMathTest::complex_cmath_cov() + { + using namespace std; + { + complex c1 ( 5,5 ); + complex c2 ( 5,5 ); + complex c3 ( 5,5 ); + + complex cdresult; + complex cfresult; + complex cldresult; + + CPPUNIT_CHECK( are_equals(abs(c1), (double)(sqrt(2.0)*5) )); + CPPUNIT_CHECK( are_equals(abs(c2), (float)(sqrt(2.0)*5) )); + CPPUNIT_CHECK( are_equals(abs(c3), (long double)(sqrt(2.0)*5) )); + + double val1 = arg(c1); + float val2 = arg(c2); + long double val3 = arg(c3); + + cdresult = exp(c1); + cfresult = exp(c2); + cldresult = exp(c3); + + cdresult = log(c1); + cfresult = log(c2); + cldresult = log(c3); + + cdresult = log10(c1); + cfresult = log10(c2); + cldresult = log10(c3); + } + { + complex c1 ( 5,5 ); + complex c2 ( 5,5 ); + complex c3 ( 5,5 ); + + complex cpower1 ( 5,5 ); + complex cpower2 ( 5,5 ); + complex cpower3 ( 5,5 ); + + complex cdresult; + complex cfresult; + complex cldresult; + + double dval = 2; + float fval = 2; + long double ldval = 2; + + cdresult = pow(c1 , cpower1); + cdresult = pow(c1 , dval); + cdresult = pow(c1 , (int)2); + cdresult = pow(dval , cpower1); + + cfresult = pow(c2 , cpower2); + cfresult = pow(c2 , fval); + cfresult = pow(c2 , (int)2); + cfresult = pow(fval , cpower2); + + cldresult = pow(c3 , cpower3); + cldresult = pow(c3 , ldval); + cldresult = pow(c3 , (int)2); + cldresult = pow(ldval , cpower3); + } + { + complex c1 ( 5,5 ); + complex c2 ( 5,5 ); + complex c3 ( 5,5 ); + + complex cdresult; + complex cfresult; + complex cldresult; + + cdresult = sqrt(c1); + cfresult = sqrt(c2); + cldresult = sqrt(c3); + } + { + double pi = 3.14159265359; + complex c1( polar ( (long double)5.0 , (long double)pi / 6 ) ); + complex c2 ( polar ( (float)5.0 , (float)pi / 6 ) ); + double absc1 = abs ( c1 ); + double argc1 = arg ( c1 ); + CPPUNIT_CHECK( absc1 == 5 ); + float normc2 = norm ( c2 ); + float sqrtnormc2 = sqrt ( normc2 ); + CPPUNIT_CHECK(sqrtnormc2 == 5); + } + } + +void CMathTest::complex_templates_cov1() + { + using namespace std; + { + complex c1( 5,0 ); + complex c2 ( polar ( 3 , 0) ); + complex c3 ( 4 , 3 ); + + int dr1 = real ( c3 ); + CPPUNIT_CHECK(dr1 == 4); + int di1 = imag ( c3 ); + CPPUNIT_CHECK(di1 == 3); + + int normc2 = norm ( c2 ); + int sqrtnormc2 = sqrt ( (double)normc2 ); + CPPUNIT_CHECK(normc2 == 9); + CPPUNIT_CHECK(sqrtnormc2 == 3); + + int absc1 = abs ( c1 ); + int argc1 = arg ( c1 ); + CPPUNIT_CHECK( absc1 == 5 ); + CPPUNIT_CHECK( argc1 == 0 ); + } + {/* + complex cl1 (4 , 4); + complex cr1 ( 2,2 ); + complex cs1 = cl1/cr1; + complex cs11 ( 2,0 ); + CPPUNIT_CHECK(cs1 == cs11); + + complex cl2 (4 , 4); + int cr2 =2; + complex cs2 = cl2/cr2; + complex cs22 (2 , 2); + CPPUNIT_CHECK(cs2 == cs22); + + int cl3 = 4; + complex cr3 (2 , 2); + complex cs3 = cl3/cr3; + complex cs33 (1 , -1); + CPPUNIT_CHECK(cs3 == cs33);*/ + } + { + complex cl1 ( 3,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 * cr1; + complex cs11 (10,0); + complex cint1 ( 2,0 ); + complex cint11 ( 2,0 ); + complex csresult (4,0); + cl1 *= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + int val = 2; + cr1 *= val; + CPPUNIT_CHECK(cr1 == cs11); + cint1 *= cint11; + CPPUNIT_CHECK(csresult == cint1); + } + } +void CMathTest::complex_templates_cov2() + { + using namespace std; + { + complex cl1 ( 3,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 + cr1; + complex cs11 (7,0); + complex cint1 ( 2,0 ); + complex cint11 ( 2,0 ); + complex csresult (4,0); + cl1 += cr1; + CPPUNIT_CHECK(cs1 == cl1); + + int val = 2; + cr1 += val; + CPPUNIT_CHECK(cr1 == cs11); + cint1 += cint11; + CPPUNIT_CHECK(csresult == cint1); + } + { + complex cl1 ( 3,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1 - cr1; + complex cs11 (3,0); + complex cint1 ( 2,0 ); + complex cint11 ( 2,0 ); + complex csresult (0,0); + cl1 -= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + int val = 2; + cr1 -= val; + CPPUNIT_CHECK(cr1 == cs11); + cint1 -= cint11; + CPPUNIT_CHECK(csresult == cint1); + } + {/* + complex cl1 ( 10,0 ); + complex cr1 ( 5,0 ); + complex cs1 = cl1/cr1; + complex cs11 (1,0); + complex cint1 ( 5,0 ); + complex cint11 ( 5,0 ); + complex csresult (1,0); + cl1 /= cr1; + CPPUNIT_CHECK(cs1 == cl1); + + int val = 5; + cr1 /= val; + CPPUNIT_CHECK(cr1 == cs11); + cint1 /= cint11; + CPPUNIT_CHECK(csresult == cint1); */ + } + { + complex cl1 ( 3 , 4 ); + complex cr1 ( 2 , -1 ); + cl1 = cr1; + CPPUNIT_CHECK(cl1 == cr1); + complex cl2 ( -2 , 4 ); + int cr2 =5; + cl2 = cr2; + CPPUNIT_CHECK(cl2 == cr2); + complex cl3(3, 4); + cl2 = cl3; + CPPUNIT_CHECK(cl2 == cl3); + complex cld(5, 0); + cl2 = cld; + } + } +void CMathTest::complex_constructors_cov1() + { + using namespace std; + { + complex c1; + int dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 0); + int di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 0); + } + { + complex c1(3,4) ; + complex c2(c1); + CPPUNIT_CHECK(c1 == c2); + } + { + complex c1(3.0,4.0) ; + complex c2(c1); + double dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 3); + double di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 4); + + int dr2 = real ( c2 ); + CPPUNIT_CHECK(dr1 == 3); + int di2 = imag ( c2 ); + CPPUNIT_CHECK(di1 == 4); + } + { + complex c1(5); + int dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 5); + int di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 0); + } + } +void CMathTest::complex_constructors_cov2() + { + using namespace std; + { + complex c1(3.0,4.0) ; + complex c2(4.0,5.0) ; + complex c3(c1); + complex c4(c2); + + float dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 3); + float di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 4); + + double dr3 = real ( c3 ); + CPPUNIT_CHECK(dr3 == 3); + double di3 = imag ( c3 ); + CPPUNIT_CHECK(di3 == 4); + + double dr4 = real ( c4 ); + CPPUNIT_CHECK(dr4 == 4); + double di4 = imag ( c4 ); + CPPUNIT_CHECK(di4 == 5); + } + { + complex c1(3.0,4.0) ; + complex c2(c1); + long double dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 3); + long double di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 4); + + float dr2 = real ( c2 ); + CPPUNIT_CHECK(dr1 == 3); + float di2 = imag ( c2 ); + CPPUNIT_CHECK(di1 == 4); + } + { + complex c1(3.0,4.0) ; + complex c2(c1); + float dr1 = real ( c1 ); + CPPUNIT_CHECK(dr1 == 3); + float di1 = imag ( c1 ); + CPPUNIT_CHECK(di1 == 4); + + long double dr2 = real ( c2 ); + CPPUNIT_CHECK(dr1 == 3); + long double di2 = imag ( c2 ); + CPPUNIT_CHECK(di1 == 4); + } + }