cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestService.cpp
Go to the documentation of this file.
1 #include "cdstd.h"
2 #include <UnitTest++.h>
3 #include "cddefines.h"
4 #include "thirdparty.h"
5 #include "service.h"
6 
7 namespace {
8 
9  TEST(TestFFmtRead)
10  {
11  bool lgEol;
12  char buf[128];
13  init_genrand( 330327317L );
14  for( int i=0; i < 4096; ++i )
15  {
16  double x = pow(10.,genrand_real1()*600. - 300.);
17  if( genrand_int32()%1 )
18  x *= -1.;
19  sprintf( buf, " %.16e", x );
20  long j = 1;
21  double y = FFmtRead( buf, &j, 128, &lgEol );
22  CHECK( fp_equal( x, y, 2 ) );
23  CHECK( !lgEol );
24  }
25  }
26 
27  TEST(TestPowi)
28  {
29  init_genrand( 395327317L );
30  for( int i=0; i < 2048; ++i )
31  {
32  double arg1 = genrand_real1()*200. - 100.;
33  long arg2 = (genrand_int32()%200) - 100;
34  CHECK( fp_equal( powi(arg1,arg2), pow(arg1,(double)arg2), max(abs(arg2),3) ) );
35  }
36  }
37 
38  TEST(TestPowpq)
39  {
40  init_genrand( 515337317L );
41  for( int i=0; i < 1024; ++i )
42  {
43  double arg1 = genrand_real1()*1.e50;
44  int arg2 = (genrand_int32()%9) + 1;
45  int arg3 = (genrand_int32()%8) + 2;
46  // powpq() may be more accurate than pow(), e.g. for powpq(x,1,3)...
47  CHECK( fp_equal( powpq(arg1,arg2,arg3), pow(arg1,(double)arg2/(double)arg3), 128 ) );
48  }
49  for( int i=0; i < 1024; ++i )
50  {
51  double arg1 = genrand_real1()*1.e50;
52  int arg2 = -((genrand_int32()%9) + 1);
53  int arg3 = (genrand_int32()%8) + 2;
54  CHECK( fp_equal( powpq(arg1,arg2,arg3), pow(arg1,(double)arg2/(double)arg3), 128 ) );
55  }
56  }
57 }
double genrand_real1()
unsigned long genrand_int32()
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:858
long max(int a, long b)
Definition: cddefines.h:821
double powi(double, long int)
Definition: service.cpp:690
double powpq(double x, int p, int q)
Definition: service.cpp:726
double pow(double x, int i)
Definition: cddefines.h:782
void init_genrand(unsigned long s)
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
Definition: service.cpp:393