proj home

Files   Classes   Functions   Hierarchy  

mathlibtest Class Reference

Test the mathlib objects. More...

#include <mathlibtest.h>

List of all members.

Static Public Member Functions

static void test01 (int argc, char **argv)
 Solve a 2 variable linear equation with column vector input.
static void test02 (int argc, char **argv)
 Solve a 2 variable linear equation and have same output as the first test.
static void test03 ()
 Test the integer set difference routine.
static void test04 (int argc, char **argv)
 Test intervalintersection : unordered in 1D.
static void test05 ()
 Test intervalsection::unordered with 4 different intervals.
static void test06 (int argc, char **argv)
 Test intervalintersection : unordered with two intervals in 1D.
static void test07 (int argc, char **argv)
 Test intervalintersection: unoredered in 2D.
static void test010 ()
 Test the solerInconsistent for 1D cases.
static void test011 ()
 Test the solver for 2D case.
static void test015 ()
 Test circleLine::intersection2D.


Detailed Description

Test the mathlib objects.

Definition at line 7 of file mathlibtest.h.


Member Function Documentation

void mathlibtest::test01 ( int  argc,
char **  argv 
) [static]

Solve a 2 variable linear equation with column vector input.

Definition at line 19 of file mathlibtest.cpp.

References commandline::mapvar(), SHOW, point2< T >::x, and point2< T >::y.

Referenced by main().

00020 {
00021   cout << "2D linear equation solver." << endl;
00022 
00023   
00024   point2<double> a0(3.0,2.0);
00025   point2<double> a1(5.0,-7.0);
00026   point2<double> c(10.0,3.0);
00027 
00028   commandline cmd(argc,argv);
00029   cmd.mapvar(a0.x,"a00");
00030   cmd.mapvar(a0.y,"a10");
00031   cmd.mapvar(a1.x,"a01");
00032   cmd.mapvar(a1.y,"a11");
00033   cmd.mapvar(c.x,"c0");
00034   cmd.mapvar(c.y,"c1");
00035 
00036   point2<double> x;
00037 
00038   solver<double>::d2linearequ(x,a0,a1,c);
00039 
00040   cout << SHOW(x) << endl;
00041 }

void mathlibtest::test010 (  )  [static]

Test the solerInconsistent for 1D cases.

Definition at line 220 of file mathlibtest.cpp.

References print(), and SHOW.

Referenced by main().

00221 {
00222   double a[3];
00223   double x[2];
00224   bool res;
00225 
00226   a[0]=0.1; 
00227   a[1]=3.0; 
00228   a[2]=4.0;
00229   res = solverInconsistent<double>::d1linearequ(x[0],x[1],a[0],a[1],a[2]);
00230   cout << "a[]: " << print(a,a+3) << endl;
00231   cout << "x[]: " << print(x,x+2) << endl;
00232   cout << SHOW(a[0]*x[0]+a[1]*x[1]-a[2]) << endl;
00233   cout << SHOW(res) << endl;
00234   cout << endl;
00235 
00236   a[0]=0.1; 
00237   a[1]=0.0; 
00238   a[2]=4.0;
00239   res = solverInconsistent<double>::d1linearequ(x[0],x[1],a[0],a[1],a[2]);
00240   cout << "a[]: " << print(a,a+3) << endl;
00241   cout << "x[]: " << print(x,x+2) << endl;
00242   cout << SHOW(a[0]*x[0]+a[1]*x[1]-a[2]) << endl;
00243   cout << SHOW(res) << endl;
00244   cout << endl;
00245 
00246   a[0]=0.0; 
00247   a[1]=-1.0; 
00248   a[2]=5.0;
00249   res = solverInconsistent<double>::d1linearequ(x[0],x[1],a[0],a[1],a[2]);
00250   cout << "a[]: " << print(a,a+3) << endl;
00251   cout << "x[]: " << print(x,x+2) << endl;
00252   cout << SHOW(a[0]*x[0]+a[1]*x[1]-a[2]) << endl;
00253   cout << SHOW(res) << endl;
00254   cout << endl;
00255 
00256 }

void mathlibtest::test011 (  )  [static]

Test the solver for 2D case.

Definition at line 259 of file mathlibtest.cpp.

References SHOW, point3< T >::x, point3< T >::y, and point3< T >::z.

Referenced by main().

00260 {
00261 
00262   double a[4] = {0.0,0.0,1.0,0.0};
00263   double b[4] = {2.0,1.0,0.0,-0.5};
00264 
00265 
00266   point3<double> w;
00267  
00268   bool res;
00269   res = solverInconsistent<double>::d2linearequ
00270   (
00271     w.x,w.y,w.z,
00272     a[0],a[1],a[2],a[3],
00273     b[0],b[1],b[2],b[3]
00274   );
00275 
00276   cout << SHOW(res) << endl;
00277 
00278   cout << SHOW( w.x*a[0]+w.y*a[1]+w.z*a[2]-a[3] ) << endl;
00279   cout << SHOW( w.x*b[0]+w.y*b[1]+w.z*b[2]-b[3] ) << endl;
00280 }

void mathlibtest::test015 (  )  [static]

Test circleLine::intersection2D.

Definition at line 283 of file mathlibtest.cpp.

References point2< T >::distance(), circleLine::intersection2D(), and SHOW.

Referenced by main().

00284 {
00285   cout << "Circle and line intersection test in 2D." << endl;
00286 
00287   point2<double> p0;
00288   point2<double> p1;
00289 
00290   cout << "Enter 2 2D point for the start and end of the line." << endl;
00291   
00292   point2<double> q0;
00293   point2<double> q1;
00294 
00295   cin >> q0;
00296   cin >> q1;
00297   cout << "Enter cirle radius" << endl;
00298   double radius;
00299   cin >> radius;
00300   
00301   bool res;
00302   res = circleLine::intersection2D(p0,p1,radius,q0,q1);
00303   cout << SHOW(res) << endl;
00304   if (res)
00305   {
00306     cout << SHOW(p0) << endl;
00307     cout << SHOW(p1) << endl;
00308     cout << SHOW(p0.distance()) << endl;
00309     cout << SHOW(p1.distance()) << endl;
00310   }
00311 }

void mathlibtest::test02 ( int  argc,
char **  argv 
) [static]

Solve a 2 variable linear equation and have same output as the first test.

Definition at line 43 of file mathlibtest.cpp.

References commandline::mapvar(), and SHOW.

Referenced by main().

00044 {
00045   cout << "2D linear equation solver." << endl;
00046 
00047   double a00(3.0);
00048   double a01(5.0);
00049   double a10(2.0);
00050   double a11(-7.0);
00051   double c0(10.0);
00052   double c1(3.0);
00053   double x;
00054   double y;
00055   
00056   commandline cmd(argc,argv);
00057   cmd.mapvar(a00,"a00");
00058   cmd.mapvar(a10,"a10");
00059   cmd.mapvar(a01,"a01");
00060   cmd.mapvar(a11,"a11");
00061   cmd.mapvar(c0,"c0");
00062   cmd.mapvar(c1,"c1");
00063 
00064   solver<double>::d2linearequ(x,y,a00,a01,a10,a11,c0,c1);
00065 
00066   cout << SHOW(x) << " " << SHOW(y) << endl;
00067 }

void mathlibtest::test03 (  )  [static]

Test the integer set difference routine.

Definition at line 69 of file mathlibtest.cpp.

References integersetdiff(), print(), and SHOW.

Referenced by main().

00070 {
00071   vector<uint> index;
00072   index.push_back(3);
00073   index.push_back(0);
00074   index.push_back(11);
00075   index.push_back(9);
00076   index.push_back(7);
00077 
00078   vector<uint> v2;
00079   uintc N(15);
00080   integersetdiff(v2,index,N);
00081   cout << SHOW(print(index)) << endl;
00082   cout << SHOW(print(v2)) << endl;
00083   cout << SHOW(N) << endl;
00084 
00085   
00086 
00087 }

void mathlibtest::test04 ( int  argc,
char **  argv 
) [static]

Test intervalintersection : unordered in 1D.

Definition at line 89 of file mathlibtest.cpp.

References commandline::mapvar(), SHOW, and intervalintersection::unordered().

Referenced by main().

00090 {
00091   commandline cmd(argc,argv);
00092   double a0;
00093   double a1;
00094   double b0;
00095   double b1;
00096   cmd.mapvar(a0,"a0");
00097   cmd.mapvar(a1,"a1");
00098   cmd.mapvar(b0,"b0");
00099   cmd.mapvar(b1,"b1");
00100 
00101   double c0;
00102   double c1;
00103   bool res;
00104   res = intervalintersection::unordered(c0,c1,a0,a1,b0,b1);
00105   cout << SHOW(res) << endl;
00106   cout << "( " << c0 << ", " << c1 << " )" << endl;
00107 }

void mathlibtest::test05 (  )  [static]

Test intervalsection::unordered with 4 different intervals.

Definition at line 109 of file mathlibtest.cpp.

References SHOW, and intervalintersection::unordered().

Referenced by main().

00110 {
00111   double a0;
00112   double a1;
00113   double b0;
00114   double b1;
00115   double c0;
00116   double c1;
00117   bool res;
00118 
00119   cout << "Testing 4 different interval intersection cases." << endl << endl;
00120 
00121   a0=0.1; a1=0.5;
00122   b0=0.3; b1=0.7;
00123   cout << "( " << a0 << ", " << a1 << " )  ( " << b0 << ", " << b1 << " )" << endl;
00124   res = intervalintersection::unordered(c0,c1,a0,a1,b0,b1);
00125   cout << SHOW(res) << "  ( " << c0 << ", " << c1 << " )" << endl;
00126 
00127   a0=0.1; a1=0.5;
00128   b0=0.2; b1=0.4;
00129   cout << "( " << a0 << ", " << a1 << " )  ( " << b0 << ", " << b1 << " )" << endl;
00130   res = intervalintersection::unordered(c0,c1,a0,a1,b0,b1);
00131   cout << SHOW(res) << "  ( " << c0 << ", " << c1 << " )" << endl;
00132 
00133 
00134   a0=0.1; a1=0.5;
00135   b0=0.0; b1=0.3;
00136   cout << "( " << a0 << ", " << a1 << " )  ( " << b0 << ", " << b1 << " )" << endl;
00137   res = intervalintersection::unordered(c0,c1,a0,a1,b0,b1);
00138   cout << SHOW(res) << "  ( " << c0 << ", " << c1 << " )" << endl;
00139 
00140 
00141   a0=0.1; a1=0.5;
00142   b0=0.0; b1=0.7;
00143   cout << "( " << a0 << ", " << a1 << " )  ( " << b0 << ", " << b1 << " )" << endl;
00144   res = intervalintersection::unordered(c0,c1,a0,a1,b0,b1);
00145   cout << SHOW(res) << "  ( " << c0 << ", " << c1 << " )" << endl;
00146 }

void mathlibtest::test06 ( int  argc,
char **  argv 
) [static]

Test intervalintersection : unordered with two intervals in 1D.

Definition at line 150 of file mathlibtest.cpp.

References commandline::mapvar(), SHOW, and intervalintersection::unordered().

Referenced by main().

00151 {
00152   commandline cmd(argc,argv);
00153   double a[2];
00154   double b[2];
00155 
00156   a[0] = a[1] = 0.0;
00157   b[0] = b[1] = 0.0;
00158 
00159   cmd.mapvar(a[0],"a0");
00160   cmd.mapvar(a[1],"a1");
00161 
00162   cmd.mapvar(b[0],"b0");
00163   cmd.mapvar(b[1],"b1");
00164 
00165   cout << "a = ( " << a[0] << ", " << a[1] << " )" << endl;
00166   cout << "b = ( " << b[0] << ", " << b[1] << " )" << endl;
00167 
00168   bool res;
00169   res = intervalintersection::unordered(a,b);
00170   cout << SHOW(res) << endl;
00171 }

void mathlibtest::test07 ( int  argc,
char **  argv 
) [static]

Test intervalintersection: unoredered in 2D.

Definition at line 173 of file mathlibtest.cpp.

References commandline::mapvar(), SHOW, and intervalintersection::unorderedD2().

Referenced by main().

00174 {
00175   commandline cmd(argc,argv);
00176   double a[2][2];
00177   double b[2][2];
00178 
00179   // Describe a box 
00180   // x: [ a00, a01 ]
00181   // y: [ a10, a11 ]
00182   
00183   a[0][0] = 0.2;
00184   a[0][1] = 0.3;
00185   a[1][0] = 0.1;
00186   a[1][1] = 0.7;
00187 
00188   cmd.mapvar(a[0][0],"a00");
00189   cmd.mapvar(a[0][1],"a01");
00190   cmd.mapvar(a[1][0],"a10");
00191   cmd.mapvar(a[1][1],"a11");
00192 
00193   cout << "First box" << endl;
00194   cout << "{ ( " << a[0][0] << ", " << a[0][1] << " ), ( ";
00195   cout << a[1][0] << ", " << a[1][1] << " ) }" << endl;
00196 
00197   // Describe a box 
00198   // x: [ b00, b01 ]
00199   // y: [ b10, b11 ]
00200   b[0][0] = -1.0;
00201   b[0][1] = 0.0;
00202   b[1][0] = 0.1;
00203   b[1][1] = 0.5;
00204 
00205   cmd.mapvar(b[0][0],"b00");
00206   cmd.mapvar(b[0][1],"b01");
00207   cmd.mapvar(b[1][0],"b10");
00208   cmd.mapvar(b[1][1],"b11");
00209 
00210   cout << "Second box" << endl;
00211   cout << "{ ( " << b[0][0] << ", " << b[0][1] << " ), ( ";
00212   cout << b[1][0] << ", " << b[1][1] << " ) }" << endl;
00213 
00214   bool res;
00215   res = intervalintersection::unorderedD2((double*)a,(double*)b);
00216   cout << SHOW(res) << endl;
00217 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:04 2011 for Chelton Evans Source by  doxygen 1.5.8