proj home

Files   Classes   Functions   Hierarchy  

functest.cpp

Go to the documentation of this file.
00001 #include <func.h>
00002 #include <funcstate.h>
00003 #include <functest.h>
00004 #include <point.h>
00005 #include <print.h>
00006 #include <prob_func.h>
00007 
00008 typedef point2<double> pt2;
00009 
00010 void functest::test01()
00011 {
00012   cout << "Creating a class within a function is legal" << endl;
00013   cout << "This may be used to eliminate the global name." << endl;
00014   cout << "Testing with points" << endl;
00015 
00016   pt2 p0(1.0,2.0);
00017   pt2 p1(3.5,6.0);
00018 
00019   class fred
00020   {
00021   public:
00022 
00023     pt2 p0;
00024     pt2 p1;
00025 
00026     pt2 operator()(double t)
00027       { return p0 + (p1-p0)*t; }
00028   };
00029 
00030   fred f;
00031   f.p0 = pt2(1.0,2.0);
00032   f.p1 = pt2(3.5,6.0);
00033 
00034   cout << SHOW( f(1.0) ) << endl;
00035 
00036 }
00037 
00038 void functest::test02()
00039 {
00040   funcA1V2(finterp,v0+(v1-v0)*x,x,pt2,double) f(pt2(1.0,2.0),pt2(3.5,6.0));
00041 
00042   cout << SHOW( f(1.0) ) << endl;
00043   pt2 y;
00044   f(y,1.0);
00045   cout << SHOW(y) << endl;
00046 }
00047 
00048 
00049 funcTA1(cubic2,1.0+x*(1.0+x*(1.0+x)),x);
00050 void functest::test03()
00051 {
00052   cout << "Test templated function with one argument." << endl;
00053   cubic2<double,double> f;
00054   cout << SHOW( f(5.0) ) << endl;
00055   double y;
00056   cubic2<double,double>()(y,1.0);
00057   cout << SHOW(y) << endl;
00058 }
00059 
00060 funcTA2(tri1,(1.0-u-v)*2.0+u*3.0+v*5.0,u,v);
00061 void functest::test04()
00062 {
00063   cout << "Test templated function with two arguments." << endl;
00064 
00065   tri1<double,double> f;
00066   cout << SHOW( f(0.2,0.3) ) << endl;
00067 }
00068 
00069 void functest::test05()
00070 {
00071   funcA1(hat,x*x+1.0,x,double,double);
00072   hat f;
00073   cout << SHOW(f(0.5)) << endl;
00074 }
00075 
00076 void functest::test06()
00077 {
00078   funcA2(cat,u*u+v*v+u*v,u,v,double,double);
00079   cout << SHOW( cat()(.2,.3) ) << endl;
00080 }
00081 
00082 void functest::test07()
00083 {
00084   class f1 : public funcstate< double >
00085   {
00086   public:
00087 
00088     f1() : funcstate<double>(2,true) {}
00089 
00090     doublec operator()()
00091     {
00092       double v0 = (xi[0]*xi[0]+xi[1]-11.0);
00093       double v1 = (xi[1]*xi[1]+xi[0]-7.0);
00094       xi[2] = v0*v0 + v1*v1;
00095       return xi[2];
00096     }
00097   };
00098 
00099   f1 f;
00100   f.xi[0]=1.0;
00101   f.xi[1]=0.0;
00102   f();
00103   double y=f.xi[2];
00104   cout << SHOW(y) << endl;
00105 }
00106 
00107 void functest::test08()
00108 {
00109   prob_f002 f;
00110 
00111   funchistory<double> fh(f);
00112 
00113   f.xi[0]=1.0;
00114   f.xi[1]=0.0;
00115   f();
00116   cout << printvecfunc(f.xi,f.dim+1) << endl;
00117   fh.push();
00118   f.xi[1]=1.0;
00119   f();
00120   cout << printvecfunc(f.xi,f.dim+1) << endl;
00121   fh.push();
00122   f.xi[0]=3.0;
00123   f.xi[1]=3.0;
00124   f();
00125 
00126   //cout << SHOW(f.dim) << endl;
00127 
00128   cout << printvecfunc(f.xi,f.dim+1) << endl;
00129 
00130   cout << "Restoring the previous value" << endl;
00131   fh.pop();
00132   cout << printvecfunc(f.xi,f.dim+1) << endl;
00133 
00134 /*
00135   double* t = new double[2];
00136   t[0]=.2;
00137   t[1]=.3;
00138   fh.fs.set_position(t);
00139 */
00140 
00141 }
00142 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8