proj home

Files   Classes   Functions   Hierarchy  

cirbuffarrtest.cpp

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <iostream>
00003 using namespace std;
00004 
00005 #include <cirbuffarr.h>
00006 #include <cirbuffarrtest.h>
00007 #include <print.h>
00008 
00009 void cirbuffarrtest01()
00010 {
00011   uintc n(3);
00012 
00013   double a[n];
00014   double * pa = & a[0];
00015 
00016   a[0]=0.0; a[1]=1.0; a[2]=2.0;
00017 
00018   cout << "Look at the current state." << endl;
00019   cout << print(a,a+n) << endl;
00020 
00021   cirbuffarr<double> cir(4,n);
00022 
00023   cout << "Push the current state" << endl;
00024   cir.push(pa);
00025 
00026   cout << cir << endl;
00027 
00028   cout << "Look at the first state in buffer" << endl;
00029   cout << print(cir[0],cir[0]+n) << endl;
00030 
00031   cout << "Edit the current state." << endl;
00032   a[0]=-12; a[1]=.3; a[2]=5.0;
00033   cout << "Push the current state" << endl;
00034   cir.push(pa);
00035   
00036   cout << cir << endl;
00037 
00038   cout << "Look at the state in the buffer" << endl;
00039   cout << print(cir[0],cir[0]+n) << endl;
00040 
00041   cout << "Restore the first state pushed" << endl;
00042   --cir;
00043   cout << cir << endl;
00044 
00045   cir.copyto(pa);
00046 
00047   cout << "Display the current state" << endl;
00048   cout << print(pa,pa+n) << endl;
00049 }
00050 
00051 
00052 void cirbuffarrtest02()
00053 {
00054   cout << "Circular buffer test" << endl;
00055   cout << "Testing the copyto function." << endl;
00056   uintc n(3);
00057   uintc states(4);
00058 
00059   cirbuffarr<double> cir(states,n);
00060   double a[n] = {1.2, 2.3, 5.0};
00061 
00062   cir.push(a);
00063 
00064   cir.dup();
00065   double *x = cir[1];
00066   x[0]=x[1]=x[2]=1.0;
00067   x=cir[2];
00068   x[0]= -5.0; x[1] = 12.0; x[2] = -3.2;
00069   
00070   cout << "First check the state by printing cir" << endl;
00071   cout << cir << endl;
00072 
00073   double y[n];
00074   cout << "Try copy and printing the states" << endl;
00075   for (uint i=0; i<states*2; ++i)
00076   {
00077     cir.copyto(y,i);
00078     cout << print(y,y+n) << endl;
00079   }
00080 
00081 }
00082 
00083 

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