Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #define _STLP_DO_IMPORT_CSTD_FUNCTIONS
21 //We also test math functions imported from stdlib.h or
26 #include "cppunit/cppunit_proxy.h"
28 //This test purpose is to check the right import of math.h C symbols
29 //into the std namespace so we do not use the using namespace std
35 class CMathTest : public CPPUNIT_NS::TestCase // codescanner::missingcclass
37 CPPUNIT_TEST_SUITE(CMathTest);
39 CPPUNIT_TEST(complex_double_cov1);
40 CPPUNIT_TEST(complex_double_cov2);
41 CPPUNIT_TEST(complex_double_cov3);
42 CPPUNIT_TEST(complex_double_cov4);
43 CPPUNIT_TEST(complex_float_cov1);
44 CPPUNIT_TEST(complex_float_cov2);
45 CPPUNIT_TEST(complex_float_cov3);
46 CPPUNIT_TEST(complex_float_cov4);
47 CPPUNIT_TEST(complex_longdouble_cov1);
48 CPPUNIT_TEST(complex_longdouble_cov2);
49 CPPUNIT_TEST(complex_longdouble_cov3);
50 CPPUNIT_TEST(complex_longdouble_cov4);
51 CPPUNIT_TEST(complex_trigonometric_cov);
52 CPPUNIT_TEST(complex_cmath_cov);
53 CPPUNIT_TEST(complex_templates_cov1);
54 CPPUNIT_TEST(complex_templates_cov2);
55 CPPUNIT_TEST(complex_constructors_cov1);
56 CPPUNIT_TEST(complex_constructors_cov2);
57 CPPUNIT_TEST_SUITE_END();
61 void complex_double_cov1();
62 void complex_double_cov2();
63 void complex_double_cov3();
64 void complex_double_cov4();
65 void complex_float_cov1();
66 void complex_float_cov2();
67 void complex_float_cov3();
68 void complex_float_cov4();
69 void complex_longdouble_cov1();
70 void complex_longdouble_cov2();
71 void complex_longdouble_cov3();
72 void complex_longdouble_cov4();
73 void complex_trigonometric_cov();
74 void complex_cmath_cov();
75 void complex_templates_cov1();
76 void complex_templates_cov2();
77 void complex_constructors_cov1();
78 void complex_constructors_cov2();
81 CPPUNIT_TEST_SUITE_REGISTRATION(CMathTest);
84 // tests implementation
86 void CMathTest::test()
90 float float_val = -1.0f;
91 double double_val = -1.0;
92 #if !defined (_STLP_NO_LONG_DOUBLE)
93 long double long_double_val = -1.0l;
96 CPPUNIT_CHECK( are_equals(std::abs(int_val), -int_val) );
97 CPPUNIT_CHECK( are_equals(std::abs(long_val), -long_val) );
98 CPPUNIT_CHECK( are_equals(std::labs(long_val), -long_val) );
99 CPPUNIT_CHECK( are_equals(std::abs(float_val), -float_val) );
100 CPPUNIT_CHECK( are_equals(std::abs(double_val), -double_val) );
101 #if !defined (_STLP_NO_LONG_DOUBLE)
102 CPPUNIT_CHECK( are_equals(std::abs(long_double_val), -long_double_val) );
105 CPPUNIT_CHECK( are_equals(std::fabs(float_val), -float_val) );
106 CPPUNIT_CHECK( are_equals(std::fabs(double_val), -double_val) );
107 #if !defined (_STLP_NO_LONG_DOUBLE)
108 CPPUNIT_CHECK( are_equals(std::fabs(long_double_val), -long_double_val) );
111 std::div_t div_res = std::div(3, 2);
112 CPPUNIT_CHECK( div_res.quot == 1 );
113 CPPUNIT_CHECK( div_res.rem == 1 );
114 std::ldiv_t ldiv_res = std::ldiv(3l, 2l);
115 CPPUNIT_CHECK( ldiv_res.quot == 1l );
116 CPPUNIT_CHECK( ldiv_res.rem == 1l );
117 ldiv_res = std::div(3l, 2l);
118 CPPUNIT_CHECK( ldiv_res.quot == 1l );
119 CPPUNIT_CHECK( ldiv_res.rem == 1l );
122 int rand_val = std::rand();
123 CPPUNIT_CHECK( rand_val >= 0 && rand_val <= RAND_MAX );
125 CPPUNIT_CHECK( are_equals(std::floor(1.5), 1.0) );
126 CPPUNIT_CHECK( are_equals(std::ceil(1.5), 2.0) );
127 CPPUNIT_CHECK( are_equals(std::fmod(1.5, 1.0), 0.5) );
128 CPPUNIT_CHECK( are_equals(std::sqrt(4.0), 2.0) );
129 CPPUNIT_CHECK( are_equals(std::pow(2.0, 2), 4.0) );
131 * Uncomment the following to check that it generates an ambiguous call
132 * as there is no Standard pow(int, int) function only pow(double, int),
133 * pow(float, int) and some others...
134 * If it do not generate a compile time error it should at least give
137 //CPPUNIT_CHECK( are_equals(std::pow(10, -2), 0.01) );
138 CPPUNIT_CHECK( are_equals(std::pow(10.0, -2), 0.01) );
139 CPPUNIT_CHECK( are_equals(std::exp(0.0), 1.0) );
140 CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0)), 1.0) );
141 CPPUNIT_CHECK( are_equals(std::log10(100.0), 2.0) );
142 #if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64)
143 CPPUNIT_CHECK( are_equals(std::modf(100.5, &double_val), 0.5) );
144 CPPUNIT_CHECK( are_equals(double_val, 100.0) );
146 double_val = std::frexp(8.0, &int_val);
147 CPPUNIT_CHECK( are_equals(double_val * std::pow(2.0, int_val), 8.0) );
148 CPPUNIT_CHECK( are_equals(std::ldexp(1.0, 2), 4.0) );
149 CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0)), 1.0) );
150 CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0)), 1.0) );
151 CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0)), 1.0) );
152 CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0, 1.0)), 1.0) );
153 CPPUNIT_CHECK( are_equals(std::cosh(0.0), 1.0) );
154 CPPUNIT_CHECK( are_equals(std::sinh(0.0), 0.0) );
155 #if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64)
156 CPPUNIT_CHECK( are_equals(std::tanh(0.0), 0.0) );
159 CPPUNIT_CHECK( are_equals(std::floor(1.5f), 1.0f) );
160 CPPUNIT_CHECK( are_equals(std::ceil(1.5f), 2.0f) );
161 CPPUNIT_CHECK( are_equals(std::fmod(1.5f, 1.0f), 0.5f) );
162 CPPUNIT_CHECK( are_equals(std::sqrt(4.0f), 2.0f) );
163 CPPUNIT_CHECK( are_equals(std::pow(2.0f, 2), 4.0f) );
164 CPPUNIT_CHECK( are_equals(std::exp(0.0f), 1.0f) );
165 CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0f)), 1.0f) );
166 CPPUNIT_CHECK( are_equals(std::log10(100.0f), 2.0f) );
167 #if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64)
168 CPPUNIT_CHECK( are_equals(std::modf(100.5f, &float_val), 0.5f) );
169 CPPUNIT_CHECK( are_equals(float_val, 100.0f) );
171 float_val = std::frexp(8.0f, &int_val);
172 CPPUNIT_CHECK( are_equals(float_val * std::pow(2.0f, int_val), 8.0f) );
173 CPPUNIT_CHECK( are_equals(std::ldexp(1.0f, 2), 4.0f) );
174 CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0f)), 1.0f) );
175 CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0f)), 1.0f) );
176 CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0f)), 1.0f) );
177 CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0f, 1.0f)), 1.0f) );
178 CPPUNIT_CHECK( are_equals(std::cosh(0.0f), 1.0f) );
179 CPPUNIT_CHECK( are_equals(std::sinh(0.0f), 0.0f) );
180 #if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64)
181 CPPUNIT_CHECK( are_equals(std::tanh(0.0f), 0.0f) );
184 #if !defined (_STLP_NO_LONG_DOUBLE)
185 CPPUNIT_CHECK( are_equals(std::floor(1.5l), 1.0l) );
186 CPPUNIT_CHECK( are_equals(std::ceil(1.5l), 2.0l) );
187 CPPUNIT_CHECK( are_equals(std::fmod(1.5l, 1.0l), 0.5l) );
188 CPPUNIT_CHECK( are_equals(std::sqrt(4.0l), 2.0l) );
189 CPPUNIT_CHECK( are_equals(std::pow(2.0l, 2), 4.0l) );
190 CPPUNIT_CHECK( are_equals(std::exp(0.0l), 1.0l) );
191 CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0l)), 1.0l) );
192 CPPUNIT_CHECK( are_equals(std::log10(100.0l), 2.0l) );
193 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64)
194 CPPUNIT_CHECK( are_equals(std::modf(100.5l, &long_double_val), 0.5l) );
195 CPPUNIT_CHECK( are_equals(long_double_val, 100.0l) );
197 long_double_val = std::frexp(8.0l, &int_val);
198 CPPUNIT_CHECK( are_equals(long_double_val * std::pow(2.0l, int_val), 8.0l) );
199 CPPUNIT_CHECK( are_equals(std::ldexp(1.0l, 2), 4.0l) );
200 CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0l)), 1.0l) );
201 CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0l)), 1.0l) );
202 CPPUNIT_CHECK( are_equals(std::tan(0.0l), 0.0l) );
203 CPPUNIT_CHECK( are_equals(std::atan(0.0l), 0.0l) );
204 CPPUNIT_CHECK( are_equals(std::atan2(0.0l, 1.0l), 0.0l) );
205 CPPUNIT_CHECK( are_equals(std::cosh(0.0l), 1.0l) );
206 CPPUNIT_CHECK( are_equals(std::sinh(0.0l), 0.0l) );
207 # if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64)
208 CPPUNIT_CHECK( are_equals(std::tanh(0.0l), 0.0l) );
212 CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0))), 2.0) );
213 CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0f))), 2.0f) );
214 #if !defined (_STLP_NO_LONG_DOUBLE)
215 CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0l))), 2.0l) );
218 void CMathTest::complex_double_cov1()
221 double pi = 3.14159265359;
222 // Test Case for abs,arg abd SQRT
224 complex <double> c1( polar ( 5.0 ) );
225 complex <double> c2 ( polar ( 5.0 , pi / 6 ) );
226 double absc1 = abs ( c1 );
227 double argc1 = arg ( c1 );
228 CPPUNIT_CHECK( absc1 == 5 );
229 CPPUNIT_CHECK( argc1 == 0 );
230 double normc2 = norm ( c2 );
231 double sqrtnormc2 = sqrt ( normc2 );
232 CPPUNIT_CHECK(sqrtnormc2 == 5);
234 // Test case for the real,imag and conj
236 complex <double> c1 ( 4.0 , 3.0 );
237 double dr1 = real ( c1 );
238 CPPUNIT_CHECK(dr1 == 4);
239 double di1 = imag ( c1 );
240 CPPUNIT_CHECK(di1 == 3);
241 complex <double> c2 = conj ( c1 );
242 double dr2 = real ( c2 );
243 CPPUNIT_CHECK(dr2 == 4);
244 double di2 = imag ( c2 );
245 CPPUNIT_CHECK(di2 == -3);
247 // test case for the operator "=" , the 3 templates
249 complex <double> cl1 ( polar (3.0 , pi / 6 ) );
250 complex <double> cr1a ( polar (2.0 , pi /3 ) );
251 complex <double> cr1b ( polar (2.0 , pi / 3 ) );
252 CPPUNIT_CHECK(cl1 != cr1a);
253 CPPUNIT_CHECK(cr1b == cr1a);
257 complex <double> cr3a ( 3 , 4 );
258 complex <double> cr3b ( 5 ,0 );
259 CPPUNIT_CHECK(cl3a != cr3a);
260 CPPUNIT_CHECK(cl3b == cr3b);
262 complex <int> cl2a ( 3 , 4 );
263 complex <int> cl2b ( 5 ,0 );
265 CPPUNIT_CHECK(cl2a != cr2a);
268 void CMathTest::complex_double_cov2()
271 double pi = 3.14159265359;
272 // test case for the operator "*" , the 3 templates
274 complex <double> cl1 ( polar (3.0 , pi / 6 ) );
275 complex <double> cr1 ( 5,0 );
276 complex <double> cs1 = cl1 * cr1;
277 complex <double> cl2 ( polar ( 3.0 , pi / 6 ) );
279 complex <double> cs2 = cl2 * cr2;
281 complex <double> cr3 ( polar (3.0 , pi / 6 ) );
282 complex <double> cs3 = cl3 * cr3;
284 CPPUNIT_CHECK(cs1 == cs2);
285 CPPUNIT_CHECK(cs3 == cs2);
287 // test case for the operator "+" , the 3 templates
289 complex <double> cl1 ( polar (3.0 , pi / 6 ) );
290 complex <double> cr1 ( 5,0 );
291 complex <double> cs1 = cl1 + cr1;
292 complex <double> cl2 ( polar ( 3.0 , pi / 6 ) );
294 complex <double> cs2 = cl2 + cr2;
296 complex <double> cr3 ( polar (3.0 , pi / 6 ) );
297 complex <double> cs3 = cl3 + cr3;
299 complex <double> cr4 ( 3.0 , 4.0 );
300 complex <double> cs4 = + cr4;
302 CPPUNIT_CHECK(cs4 == cr4);
303 CPPUNIT_CHECK(cs1 == cs2);
304 CPPUNIT_CHECK(cs3 == cs2);
306 // test case for the operator "-" , the 3 templates
308 complex <double> cl1 (3 , 4);
309 complex <double> cr1 ( 2,3 );
310 complex <double> cs1 = cl1 - cr1;
311 complex <double> cs11 ( 1,1 );
312 CPPUNIT_CHECK(cs1 == cs11);
314 complex <double> cl2 (3 , 4);
316 complex <double> cs2 = cl2 - cr2;
317 complex <double> cs22 (-2 , 4);
318 CPPUNIT_CHECK(cs2 == cs22);
321 complex <double> cr3 (3 , 4);
322 complex <double> cs3 = cl3 - cr3;
323 complex <double> cs33 (2 , -4);
324 CPPUNIT_CHECK(cs3 == cs33);
326 complex <double> cr4 ( 3 , 4 );
327 complex <double> cs4 = -cr4;
328 complex <double> cs44 (-3 , -4);
329 CPPUNIT_CHECK(cs4 == cs44);
331 // test case for the operator "/" , the 3 templates
333 complex <double> cl1 (4 , 4);
334 complex <double> cr1 ( 2,2 );
335 complex <double> cs1 = cl1/cr1;
336 complex <double> cs11 ( 2,0 );
337 CPPUNIT_CHECK(cs1 == cs11);
339 complex <double> cl2 (4 , 4);
341 complex <double> cs2 = cl2/cr2;
342 complex <double> cs22 (2 , 2);
343 CPPUNIT_CHECK(cs2 == cs22);
346 complex <double> cr3 (2 , 2);
347 complex <double> cs3 = cl3/cr3;
348 complex <double> cs33 (1 , -1);
349 CPPUNIT_CHECK(cs3 == cs33);
353 void CMathTest::complex_double_cov3()
356 double pi = 3.14159265359;
357 // test case for the operator "*=" , the 3 templates
359 complex <double> cl1 ( polar (3.0 , pi / 6 ) );
360 complex <double> cr1 ( 5,0 );
361 complex <double> cs1 = cl1 * cr1;
362 complex <double> cs11 (10,0);
363 complex <int> cint1 ( 2,0 );
364 complex <double> csresult (20,0);
366 CPPUNIT_CHECK(cs1 == cl1);
370 CPPUNIT_CHECK(cr1 == cs11);
372 CPPUNIT_CHECK(csresult == cs11);
374 // test case for the operator "+=" , the 3 templates
376 complex <double> cl1 ( polar (3.0 , pi / 6 ) );
377 complex <double> cr1 ( 5,0 );
378 complex <double> cs1 = cl1 + cr1;
379 complex <double> cs11 (7,0);
380 complex <int> cint1 ( 2,0 );
381 complex <double> csresult (9,0);
383 CPPUNIT_CHECK(cs1 == cl1);
387 CPPUNIT_CHECK(cr1 == cs11);
389 CPPUNIT_CHECK(csresult == cs11);
393 void CMathTest::complex_double_cov4()
396 double pi = 3.14159265359;
397 // test case for the operator "-=" , the 3 templates
399 complex <double> cl1 ( polar (3.0 , pi / 6 ) );
400 complex <double> cr1 ( 5,0 );
401 complex <double> cs1 = cl1 - cr1;
402 complex <double> cs11 (3,0);
403 complex <int> cint1 ( 2,0 );
404 complex <double> csresult (1,0);
406 CPPUNIT_CHECK(cs1 == cl1);
410 CPPUNIT_CHECK(cr1 == cs11);
412 CPPUNIT_CHECK(csresult == cs11);
414 // test case for the operator "/=" , the 3 templates
416 complex <double> cl1 ( 10,0 );
417 complex <double> cr1 ( 5,0 );
418 complex <double> cs1 = cl1/cr1;
419 complex <double> cs11 (1,0);
420 complex <int> cint1 ( 1,0 );
421 complex <double> csresult (1,0);
423 CPPUNIT_CHECK(cs1 == cl1);
427 CPPUNIT_CHECK(cr1 == cs11);
429 CPPUNIT_CHECK(csresult == cs11);
431 // test case for the operator "=" , the 3 templates
433 complex <double> cl1 ( 3.0 , 4.0 );
434 complex <double> cr1 ( 2.0 , -1.0 );
436 CPPUNIT_CHECK(cl1 == cr1);
437 complex <double> cl2 ( -2 , 4 );
440 CPPUNIT_CHECK(cl2 == cr2);
441 complex<double> cl3(3.0, 4.0);
443 CPPUNIT_CHECK(cl2 == cl3);
447 void CMathTest::complex_float_cov1()
450 // test case for the abs,arg and sqrt
452 complex <float> c1( polar ( 5.0 ) );
453 complex <float> c2 ( 5,0 );
454 float absc1 = abs ( c1 );
455 float argc1 = arg ( c1 );
456 CPPUNIT_CHECK( absc1 == 5 );
457 CPPUNIT_CHECK( argc1 == 0 );
458 float normc2 = norm ( c2 );
460 float sqrtnormc2 = sqrt ( normc2 );
461 CPPUNIT_CHECK(normc2 == val);
462 CPPUNIT_CHECK(sqrtnormc2 == 5);
464 // test case for the real,imag and conj
466 complex <float> c1 ( 4.0 , 3.0 );
467 float dr1 = real ( c1 );
468 CPPUNIT_CHECK(dr1 == 4);
469 float di1 = imag ( c1 );
470 CPPUNIT_CHECK(di1 == 3);
471 complex <float> c2 = conj ( c1 );
472 float dr2 = real ( c2 );
473 CPPUNIT_CHECK(dr2 == 4);
474 float di2 = imag ( c2 );
475 CPPUNIT_CHECK(di2 == -3);
477 // test case for the operator "=" , the 3 templates
479 complex <float> cl1 ( 7,7 );
480 complex <float> cr1a ( 5,7 );
481 complex <float> cr1b ( 5,7 );
482 CPPUNIT_CHECK(cl1 != cr1a);
483 CPPUNIT_CHECK(cr1b == cr1a);
487 complex <float> cr3a ( 3 , 4 );
488 complex <float> cr3b ( 5 ,0 );
489 CPPUNIT_CHECK(cl3a != cr3a);
490 CPPUNIT_CHECK(cl3b == cr3b);
492 complex <int> cl2a ( 3 , 4 );
493 complex <int> cl2b ( 5 ,0 );
495 CPPUNIT_CHECK(cl2a != cr2a);
498 void CMathTest::complex_float_cov2()
501 // test case for the operator "*" , the 3 templates
503 complex <float> cl1 ( 7,5 );
504 complex <float> cr1 ( 5,0 );
505 complex <float> cs1 = cl1 * cr1;
506 complex <float> cl2 ( 7,5 );
508 complex <float> cs2 = cl2 * cr2;
510 complex <float> cr3 ( 7,5 );
511 complex <float> cs3 = cl3 * cr3;
513 CPPUNIT_CHECK(cs1 == cs2);
514 CPPUNIT_CHECK(cs3 == cs2);
516 // test case for the operator "+" , the 3 templates
518 complex <float> cl1 ( 7,0 );
519 complex <float> cr1 ( 5,0 );
520 complex <float> cs1 = cl1 + cr1;
521 complex <float> cl2 ( 7,0 );
523 complex <float> cs2 = cl2 + cr2;
525 complex <float> cr3 ( 7,0 );
526 complex <float> cs3 = cl3 + cr3;
528 complex <float> cr4 ( 3.0 , 4.0 );
529 complex <float> cs4 = + cr4;
531 CPPUNIT_CHECK(cs4 == cr4);
532 CPPUNIT_CHECK(cs1 == cs2);
533 CPPUNIT_CHECK(cs3 == cs2);
535 // test case for the operator "-" , the 3 templates
537 complex <float> cl1 (3 , 4);
538 complex <float> cr1 ( 2,3 );
539 complex <float> cs1 = cl1 - cr1;
540 complex <float> cs11 ( 1,1 );
541 CPPUNIT_CHECK(cs1 == cs11);
543 complex <float> cl2 (3 , 4);
545 complex <float> cs2 = cl2 - cr2;
546 complex <float> cs22 (-2 , 4);
547 CPPUNIT_CHECK(cs2 == cs22);
550 complex <float> cr3 (3 , 4);
551 complex <float> cs3 = cl3 - cr3;
552 complex <float> cs33 (2 , -4);
553 CPPUNIT_CHECK(cs3 == cs33);
555 complex <float> cr4 ( 3 , 4 );
556 complex <float> cs4 = -cr4;
557 complex <float> cs44 (-3 , -4);
558 CPPUNIT_CHECK(cs4 == cs44);
560 // test case for the operator "/" , the 3 templates
562 complex <float> cl1 (4 , 4);
563 complex <float> cr1 ( 2,2 );
564 complex <float> cs1 = cl1/cr1;
565 complex <float> cs11 ( 2,0 );
566 CPPUNIT_CHECK(cs1 == cs11);
568 complex <float> cl2 (4 , 4);
570 complex <float> cs2 = cl2/cr2;
571 complex <float> cs22 (2 , 2);
572 CPPUNIT_CHECK(cs2 == cs22);
575 complex <float> cr3 (2 , 2);
576 complex <float> cs3 = cl3/cr3;
577 complex <float> cs33 (1 , -1);
578 CPPUNIT_CHECK(cs3 == cs33);
581 void CMathTest::complex_float_cov3()
584 // test case for the operator "*=" , the 3 templates
586 complex <float> cl1 ( 7,0 );
587 complex <float> cr1 ( 5,0 );
588 complex <float> cs1 = cl1 * cr1;
589 complex <float> cs11 (10,0);
590 complex <int> cint1 ( 2,0 );
591 complex <float> csresult (20,0);
593 CPPUNIT_CHECK(cs1 == cl1);
597 CPPUNIT_CHECK(cr1 == cs11);
599 CPPUNIT_CHECK(csresult == cs11);
601 // test case for the operator "+=" , the 3 templates
603 complex <float> cl1 ( 7,0 );
604 complex <float> cr1 ( 5,0 );
605 complex <float> cs1 = cl1 + cr1;
606 complex <float> cs11 (7,0);
607 complex <int> cint1 ( 2,0 );
608 complex <float> csresult (9,0);
610 CPPUNIT_CHECK(cs1 == cl1);
614 CPPUNIT_CHECK(cr1 == cs11);
616 CPPUNIT_CHECK(csresult == cs11);
618 // test case for the operator "-=" , the 3 templates
620 complex <float> cl1 ( 7,7 );
621 complex <float> cr1 ( 5,0 );
622 complex <float> cs1 = cl1 - cr1;
623 complex <float> cs11 (3,0);
624 complex <int> cint1 ( 2,0 );
625 complex <float> csresult (1,0);
627 CPPUNIT_CHECK(cs1 == cl1);
631 CPPUNIT_CHECK(cr1 == cs11);
633 CPPUNIT_CHECK(csresult == cs11);
636 void CMathTest::complex_float_cov4()
639 // test case for the operator "/=" , the 3 templates
641 complex <float> cl1 ( 10,0 );
642 complex <float> cr1 ( 5,0 );
643 complex <float> cs1 = cl1/cr1;
644 complex <float> cs11 (1,0);
645 complex <int> cint1 ( 1,0 );
646 complex <float> csresult (1,0);
648 CPPUNIT_CHECK(cs1 == cl1);
652 CPPUNIT_CHECK(cr1 == cs11);
654 CPPUNIT_CHECK(csresult == cs11);
656 // test case for the operator "=" , the 3 templates
658 complex <float> cl1 ( 3.0 , 4.0 );
659 complex <float> cr1 ( 2.0 , -1.0 );
661 CPPUNIT_CHECK(cl1 == cr1);
662 complex <float> cl2 ( -2 , 4 );
665 CPPUNIT_CHECK(cl2 == cr2);
666 complex<float> cl3(3.0, 4.0);
668 CPPUNIT_CHECK(cl2 == cl3);
672 void CMathTest::complex_longdouble_cov1()
675 // test case for the abs,arg and sqrt
677 complex <long double> c1( polar ( 5.0 ) );
678 complex <long double> c2 ( 5,0 );
679 long double absc1 = abs ( c1 );
680 long double argc1 = arg ( c1 );
681 CPPUNIT_CHECK( absc1 == 5 );
682 CPPUNIT_CHECK( argc1 == 0 );
683 long double normc2 = norm ( c2 );
684 long double val = 25;
685 long double sqrtnormc2 = sqrt ( normc2 );
686 CPPUNIT_CHECK(normc2 == val);
687 CPPUNIT_CHECK(sqrtnormc2 == 5);
689 // test case for the real,imag and conj
691 complex <long double> c1 ( 4.0 , 3.0 );
692 long double dr1 = real ( c1 );
693 CPPUNIT_CHECK(dr1 == 4);
694 long double di1 = imag ( c1 );
695 CPPUNIT_CHECK(di1 == 3);
696 complex <long double> c2 = conj ( c1 );
697 long double dr2 = real ( c2 );
698 CPPUNIT_CHECK(dr2 == 4);
699 long double di2 = imag ( c2 );
700 CPPUNIT_CHECK(di2 == -3);
702 // test case for the operator "=" , the 3 templates
704 complex <long double> cl1 ( 7,7 );
705 complex <long double> cr1a ( 5,7 );
706 complex <long double> cr1b ( 5,7 );
707 CPPUNIT_CHECK(cl1 != cr1a);
708 CPPUNIT_CHECK(cr1b == cr1a);
712 complex <long double> cr3a ( 3 , 4 );
713 complex <long double> cr3b ( 5 ,0 );
714 CPPUNIT_CHECK(cl3a != cr3a);
715 CPPUNIT_CHECK(cl3b == cr3b);
717 complex <int> cl2a ( 3 , 4 );
718 complex <int> cl2b ( 5 ,0 );
720 CPPUNIT_CHECK(cl2a != cr2a);
723 void CMathTest::complex_longdouble_cov2()
726 // test case for the operator "*" , the 3 templates
728 complex <long double> cl1 ( 7,5 );
729 complex <long double> cr1 ( 5,0 );
730 complex <long double> cs1 = cl1 * cr1;
731 complex <long double> cl2 ( 7,5 );
733 complex <long double> cs2 = cl2 * cr2;
735 complex <long double> cr3 ( 7,5 );
736 complex <long double> cs3 = cl3 * cr3;
738 CPPUNIT_CHECK(cs1 == cs2);
739 CPPUNIT_CHECK(cs3 == cs2);
741 // test case for the operator "+" , the 3 templates
743 complex <long double> cl1 ( 7,0 );
744 complex <long double> cr1 ( 5,0 );
745 complex <long double> cs1 = cl1 + cr1;
746 complex <long double> cl2 ( 7,0 );
748 complex <long double> cs2 = cl2 + cr2;
750 complex <long double> cr3 ( 7,0 );
751 complex <long double> cs3 = cl3 + cr3;
753 complex <long double> cr4 ( 3.0 , 4.0 );
754 complex <long double> cs4 = + cr4;
756 CPPUNIT_CHECK(cs4 == cr4);
757 CPPUNIT_CHECK(cs1 == cs2);
758 CPPUNIT_CHECK(cs3 == cs2);
760 // test case for the operator "-" , the 3 templates
762 complex <long double> cl1 (3 , 4);
763 complex <long double> cr1 ( 2,3 );
764 complex <long double> cs1 = cl1 - cr1;
765 complex <long double> cs11 ( 1,1 );
766 CPPUNIT_CHECK(cs1 == cs11);
768 complex <long double> cl2 (3 , 4);
770 complex <long double> cs2 = cl2 - cr2;
771 complex <long double> cs22 (-2 , 4);
772 CPPUNIT_CHECK(cs2 == cs22);
775 complex <long double> cr3 (3 , 4);
776 complex <long double> cs3 = cl3 - cr3;
777 complex <long double> cs33 (2 , -4);
778 CPPUNIT_CHECK(cs3 == cs33);
780 complex <long double> cr4 ( 3 , 4 );
781 complex <long double> cs4 = -cr4;
782 complex <long double> cs44 (-3 , -4);
783 CPPUNIT_CHECK(cs4 == cs44);
785 // test case for the operator "/" , the 3 templates
787 complex <long double> cl1 (4 , 4);
788 complex <long double> cr1 ( 2,2 );
789 complex <long double> cs1 = cl1/cr1;
790 complex <long double> cs11 ( 2,0 );
791 CPPUNIT_CHECK(cs1 == cs11);
793 complex <long double> cl2 (4 , 4);
795 complex <long double> cs2 = cl2/cr2;
796 complex <long double> cs22 (2 , 2);
797 CPPUNIT_CHECK(cs2 == cs22);
800 complex <long double> cr3 (2 , 2);
801 complex <long double> cs3 = cl3/cr3;
802 complex <long double> cs33 (1 , -1);
803 CPPUNIT_CHECK(cs3 == cs33);
806 void CMathTest::complex_longdouble_cov3()
809 // test case for the operator "*=" , the 3 templates
811 complex <long double> cl1 ( 7,0 );
812 complex <long double> cr1 ( 5,0 );
813 complex <long double> cs1 = cl1 * cr1;
814 complex <long double> cs11 (10,0);
815 complex <int> cint1 ( 2,0 );
816 complex <long double> csresult (20,0);
818 CPPUNIT_CHECK(cs1 == cl1);
822 CPPUNIT_CHECK(cr1 == cs11);
824 CPPUNIT_CHECK(csresult == cs11);
826 // test case for the operator "+=" , the 3 templates
828 complex <long double> cl1 ( 7,0 );
829 complex <long double> cr1 ( 5,0 );
830 complex <long double> cs1 = cl1 + cr1;
831 complex <long double> cs11 (7,0);
832 complex <int> cint1 ( 2,0 );
833 complex <long double> csresult (9,0);
835 CPPUNIT_CHECK(cs1 == cl1);
839 CPPUNIT_CHECK(cr1 == cs11);
841 CPPUNIT_CHECK(csresult == cs11);
844 void CMathTest::complex_longdouble_cov4()
847 // test case for the operator "-=" , the 3 templates
849 complex <long double> cl1 ( 7,7 );
850 complex <long double> cr1 ( 5,0 );
851 complex <long double> cs1 = cl1 - cr1;
852 complex <long double> cs11 (3,0);
853 complex <int> cint1 ( 2,0 );
854 complex <long double> csresult (1,0);
856 CPPUNIT_CHECK(cs1 == cl1);
860 CPPUNIT_CHECK(cr1 == cs11);
862 CPPUNIT_CHECK(csresult == cs11);
864 // test case for the operator "/=" , the 3 templates
866 complex <long double> cl1 ( 10,0 );
867 complex <long double> cr1 ( 5,0 );
868 complex <long double> cs1 = cl1/cr1;
869 complex <long double> cs11 (1,0);
870 complex <int> cint1 ( 1,0 );
871 complex <long double> csresult (1,0);
873 CPPUNIT_CHECK(cs1 == cl1);
877 CPPUNIT_CHECK(cr1 == cs11);
879 CPPUNIT_CHECK(csresult == cs11);
881 // test case for the operator "=" , the 3 templates
883 complex <long double> cl1 ( 3.0 , 4.0 );
884 complex <long double> cr1 ( 2.0 , -1.0 );
886 CPPUNIT_CHECK(cl1 == cr1);
887 complex <long double> cl2 ( -2 , 4 );
888 long double cr2 =5.0;
890 CPPUNIT_CHECK(cl2 == cr2);
891 complex<long double> cl3(3.0, 4.0);
893 CPPUNIT_CHECK(cl2 == cl3);
896 void CMathTest::complex_trigonometric_cov()
900 complex <double> c1 ( 5,0 );
901 complex <float> c2 ( 5,0 );
902 complex <long double> c3 ( 5,0 );
904 complex <double> cdresult;
905 complex <float> cfresult;
906 complex <long double> cldresult;
908 cdresult = cos ( c1 );
909 cfresult = cos ( c2 );
910 cldresult = cos ( c3 );
912 cdresult = cosh ( c1 );
913 cfresult = cosh ( c2 );
914 cldresult = cosh ( c3 );
916 cdresult = sin ( c1 );
917 cfresult = sin ( c2 );
918 cldresult = sin ( c3 );
920 cdresult = sinh ( c1 );
921 cfresult = sinh ( c2 );
922 cldresult = sinh ( c3 );
924 cdresult = tan ( c1 );
925 cfresult = tan ( c2 );
926 cldresult = tan ( c3 );
928 cdresult = tanh ( c1 );
929 cfresult = tanh ( c2 );
930 cldresult = tanh ( c3 );
933 void CMathTest::complex_cmath_cov()
937 complex <double> c1 ( 5,5 );
938 complex <float> c2 ( 5,5 );
939 complex <long double> c3 ( 5,5 );
941 complex <double> cdresult;
942 complex <float> cfresult;
943 complex <long double> cldresult;
945 CPPUNIT_CHECK( are_equals(abs(c1), (double)(sqrt(2.0)*5) ));
946 CPPUNIT_CHECK( are_equals(abs(c2), (float)(sqrt(2.0)*5) ));
947 CPPUNIT_CHECK( are_equals(abs(c3), (long double)(sqrt(2.0)*5) ));
949 double val1 = arg(c1);
950 float val2 = arg(c2);
951 long double val3 = arg(c3);
961 cdresult = log10(c1);
962 cfresult = log10(c2);
963 cldresult = log10(c3);
966 complex <double> c1 ( 5,5 );
967 complex <float> c2 ( 5,5 );
968 complex <long double> c3 ( 5,5 );
970 complex <double> cpower1 ( 5,5 );
971 complex <float> cpower2 ( 5,5 );
972 complex <long double> cpower3 ( 5,5 );
974 complex <double> cdresult;
975 complex <float> cfresult;
976 complex <long double> cldresult;
980 long double ldval = 2;
982 cdresult = pow(c1 , cpower1);
983 cdresult = pow(c1 , dval);
984 cdresult = pow(c1 , (int)2);
985 cdresult = pow(dval , cpower1);
987 cfresult = pow(c2 , cpower2);
988 cfresult = pow(c2 , fval);
989 cfresult = pow(c2 , (int)2);
990 cfresult = pow(fval , cpower2);
992 cldresult = pow(c3 , cpower3);
993 cldresult = pow(c3 , ldval);
994 cldresult = pow(c3 , (int)2);
995 cldresult = pow(ldval , cpower3);
998 complex <double> c1 ( 5,5 );
999 complex <float> c2 ( 5,5 );
1000 complex <long double> c3 ( 5,5 );
1002 complex <double> cdresult;
1003 complex <float> cfresult;
1004 complex <long double> cldresult;
1006 cdresult = sqrt(c1);
1007 cfresult = sqrt(c2);
1008 cldresult = sqrt(c3);
1011 double pi = 3.14159265359;
1012 complex <double> c1( polar ( (long double)5.0 , (long double)pi / 6 ) );
1013 complex <double> c2 ( polar ( (float)5.0 , (float)pi / 6 ) );
1014 double absc1 = abs ( c1 );
1015 double argc1 = arg ( c1 );
1016 CPPUNIT_CHECK( absc1 == 5 );
1017 float normc2 = norm ( c2 );
1018 float sqrtnormc2 = sqrt ( normc2 );
1019 CPPUNIT_CHECK(sqrtnormc2 == 5);
1023 void CMathTest::complex_templates_cov1()
1025 using namespace std;
1027 complex <int> c1( 5,0 );
1028 complex <int> c2 ( polar ( 3 , 0) );
1029 complex <int> c3 ( 4 , 3 );
1031 int dr1 = real ( c3 );
1032 CPPUNIT_CHECK(dr1 == 4);
1033 int di1 = imag ( c3 );
1034 CPPUNIT_CHECK(di1 == 3);
1036 int normc2 = norm ( c2 );
1037 int sqrtnormc2 = sqrt ( (double)normc2 );
1038 CPPUNIT_CHECK(normc2 == 9);
1039 CPPUNIT_CHECK(sqrtnormc2 == 3);
1041 int absc1 = abs ( c1 );
1042 int argc1 = arg ( c1 );
1043 CPPUNIT_CHECK( absc1 == 5 );
1044 CPPUNIT_CHECK( argc1 == 0 );
1047 complex <int> cl1 (4 , 4);
1048 complex <int> cr1 ( 2,2 );
1049 complex <int> cs1 = cl1/cr1;
1050 complex <int> cs11 ( 2,0 );
1051 CPPUNIT_CHECK(cs1 == cs11);
1053 complex <int> cl2 (4 , 4);
1055 complex <int> cs2 = cl2/cr2;
1056 complex <int> cs22 (2 , 2);
1057 CPPUNIT_CHECK(cs2 == cs22);
1060 complex <int> cr3 (2 , 2);
1061 complex <int> cs3 = cl3/cr3;
1062 complex <int> cs33 (1 , -1);
1063 CPPUNIT_CHECK(cs3 == cs33);*/
1066 complex <int> cl1 ( 3,0 );
1067 complex <int> cr1 ( 5,0 );
1068 complex <int> cs1 = cl1 * cr1;
1069 complex <int> cs11 (10,0);
1070 complex <int> cint1 ( 2,0 );
1071 complex <float> cint11 ( 2,0 );
1072 complex <int> csresult (4,0);
1074 CPPUNIT_CHECK(cs1 == cl1);
1078 CPPUNIT_CHECK(cr1 == cs11);
1080 CPPUNIT_CHECK(csresult == cint1);
1083 void CMathTest::complex_templates_cov2()
1085 using namespace std;
1087 complex <int> cl1 ( 3,0 );
1088 complex <int> cr1 ( 5,0 );
1089 complex <int> cs1 = cl1 + cr1;
1090 complex <int> cs11 (7,0);
1091 complex <int> cint1 ( 2,0 );
1092 complex <float> cint11 ( 2,0 );
1093 complex <int> csresult (4,0);
1095 CPPUNIT_CHECK(cs1 == cl1);
1099 CPPUNIT_CHECK(cr1 == cs11);
1101 CPPUNIT_CHECK(csresult == cint1);
1104 complex <int> cl1 ( 3,0 );
1105 complex <int> cr1 ( 5,0 );
1106 complex <int> cs1 = cl1 - cr1;
1107 complex <int> cs11 (3,0);
1108 complex <int> cint1 ( 2,0 );
1109 complex <float> cint11 ( 2,0 );
1110 complex <int> csresult (0,0);
1112 CPPUNIT_CHECK(cs1 == cl1);
1116 CPPUNIT_CHECK(cr1 == cs11);
1118 CPPUNIT_CHECK(csresult == cint1);
1121 complex <int> cl1 ( 10,0 );
1122 complex <int> cr1 ( 5,0 );
1123 complex <int> cs1 = cl1/cr1;
1124 complex <int> cs11 (1,0);
1125 complex <int> cint1 ( 5,0 );
1126 complex <double> cint11 ( 5,0 );
1127 complex <int> csresult (1,0);
1129 CPPUNIT_CHECK(cs1 == cl1);
1133 CPPUNIT_CHECK(cr1 == cs11);
1135 CPPUNIT_CHECK(csresult == cint1); */
1138 complex <int> cl1 ( 3 , 4 );
1139 complex <int> cr1 ( 2 , -1 );
1141 CPPUNIT_CHECK(cl1 == cr1);
1142 complex <int> cl2 ( -2 , 4 );
1145 CPPUNIT_CHECK(cl2 == cr2);
1146 complex<int> cl3(3, 4);
1148 CPPUNIT_CHECK(cl2 == cl3);
1149 complex<double> cld(5, 0);
1153 void CMathTest::complex_constructors_cov1()
1155 using namespace std;
1158 int dr1 = real ( c1 );
1159 CPPUNIT_CHECK(dr1 == 0);
1160 int di1 = imag ( c1 );
1161 CPPUNIT_CHECK(di1 == 0);
1164 complex<int> c1(3,4) ;
1165 complex<int> c2(c1);
1166 CPPUNIT_CHECK(c1 == c2);
1169 complex<double> c1(3.0,4.0) ;
1170 complex<int> c2(c1);
1171 double dr1 = real ( c1 );
1172 CPPUNIT_CHECK(dr1 == 3);
1173 double di1 = imag ( c1 );
1174 CPPUNIT_CHECK(di1 == 4);
1176 int dr2 = real ( c2 );
1177 CPPUNIT_CHECK(dr1 == 3);
1178 int di2 = imag ( c2 );
1179 CPPUNIT_CHECK(di1 == 4);
1183 int dr1 = real ( c1 );
1184 CPPUNIT_CHECK(dr1 == 5);
1185 int di1 = imag ( c1 );
1186 CPPUNIT_CHECK(di1 == 0);
1189 void CMathTest::complex_constructors_cov2()
1191 using namespace std;
1193 complex<float> c1(3.0,4.0) ;
1194 complex<long double> c2(4.0,5.0) ;
1195 complex<double> c3(c1);
1196 complex<double> c4(c2);
1198 float dr1 = real ( c1 );
1199 CPPUNIT_CHECK(dr1 == 3);
1200 float di1 = imag ( c1 );
1201 CPPUNIT_CHECK(di1 == 4);
1203 double dr3 = real ( c3 );
1204 CPPUNIT_CHECK(dr3 == 3);
1205 double di3 = imag ( c3 );
1206 CPPUNIT_CHECK(di3 == 4);
1208 double dr4 = real ( c4 );
1209 CPPUNIT_CHECK(dr4 == 4);
1210 double di4 = imag ( c4 );
1211 CPPUNIT_CHECK(di4 == 5);
1214 complex<long double> c1(3.0,4.0) ;
1215 complex<float> c2(c1);
1216 long double dr1 = real ( c1 );
1217 CPPUNIT_CHECK(dr1 == 3);
1218 long double di1 = imag ( c1 );
1219 CPPUNIT_CHECK(di1 == 4);
1221 float dr2 = real ( c2 );
1222 CPPUNIT_CHECK(dr1 == 3);
1223 float di2 = imag ( c2 );
1224 CPPUNIT_CHECK(di1 == 4);
1227 complex<float> c1(3.0,4.0) ;
1228 complex<long double> c2(c1);
1229 float dr1 = real ( c1 );
1230 CPPUNIT_CHECK(dr1 == 3);
1231 float di1 = imag ( c1 );
1232 CPPUNIT_CHECK(di1 == 4);
1234 long double dr2 = real ( c2 );
1235 CPPUNIT_CHECK(dr1 == 3);
1236 long double di2 = imag ( c2 );
1237 CPPUNIT_CHECK(di1 == 4);