#include <cassert>
#include <iostream>
using namespace std;

#include <cirbuffarr.h>
#include <cirbuffarrtest.h>
#include <print.h>

void cirbuffarrtest01()
{
  uintc n(3);

  double a[n];
  double * pa = & a[0];

  a[0]=0.0; a[1]=1.0; a[2]=2.0;

  cout << "Look at the current state." << endl;
  cout << print(a,a+n) << endl;

  cirbuffarr<double> cir(4,n);

  cout << "Push the current state" << endl;
  cir.push(pa);

  cout << cir << endl;

  cout << "Look at the first state in buffer" << endl;
  cout << print(cir[0],cir[0]+n) << endl;

  cout << "Edit the current state." << endl;
  a[0]=-12; a[1]=.3; a[2]=5.0;
  cout << "Push the current state" << endl;
  cir.push(pa);
  
  cout << cir << endl;

  cout << "Look at the state in the buffer" << endl;
  cout << print(cir[0],cir[0]+n) << endl;

  cout << "Restore the first state pushed" << endl;
  --cir;
  cout << cir << endl;

  cir.copyto(pa);

  cout << "Display the current state" << endl;
  cout << print(pa,pa+n) << endl;
}


void cirbuffarrtest02()
{
  cout << "Circular buffer test" << endl;
  cout << "Testing the copyto function." << endl;
  uintc n(3);
  uintc states(4);

  cirbuffarr<double> cir(states,n);
  double a[n] = {1.2, 2.3, 5.0};

  cir.push(a);

  cir.dup();
  double *x = cir[1];
  x[0]=x[1]=x[2]=1.0;
  x=cir[2];
  x[0]= -5.0; x[1] = 12.0; x[2] = -3.2;
  
  cout << "First check the state by printing cir" << endl;
  cout << cir << endl;

  double y[n];
  cout << "Try copy and printing the states" << endl;
  for (uint i=0; i<states*2; ++i)
  {
    cir.copyto(y,i);
    cout << print(y,y+n) << endl;
  }

}



