#include "realmat.h"
using namespace std;
using namespace scl;

int main()
{
  cout << starbox("/ivec = seq(-5,4)//") << endl;
  intvec ivec = seq(-5,4);
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;

  cout << starbox("/Does ivec.size() == ivec.size()?//") << '\n';
  cout << "  " << (ivec.size() == ivec.size()) << '\n';
 
  cout << starbox("/jvec from copy constructor and operator =//") << endl;
  intvec jvec(ivec);
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i];
  cout << endl;
  jvec = ivec;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i];
  cout << endl;
  cout << starbox("/(jvec==ivec) (jvec!=ivec) //") << endl;
  cout << "  " << (jvec==ivec) << "  " << (jvec!=ivec) ;
  cout << endl;

  cout << starbox("/ivec = seq(-5,-4)//") << endl;
  ivec = seq(-5,-4);
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;

  cout << starbox("/kvec=bind(ivec,jvec)//") << endl;
  intvec kvec=bind(ivec,jvec);
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i];
  cout << endl;

  cout << starbox("/ivec = seq(-4,-5)//") << endl;
  ivec = seq(-4,-5);
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;

  cout << starbox("/ivec = seq(0,0)//") << endl;
  ivec = seq(0,0);
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;

  cout << starbox("/jvec, jvec.check(2), jvec[1]=5, jvec[1], jvec//") << endl;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i];
  cout << endl;
  cout << "  " << jvec.check(2);
  jvec[1]=5;
  cout << "  " << jvec[1];
  cout << endl;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i];
  cout << endl;
  cout << starbox("/jvec.size(), jvec.resize(15), jvec.size()//") << endl;
  cout << "  " << jvec.size();
  jvec.resize(15); 
  cout << "  " << jvec.size();
  cout << endl;
  
  cout << starbox("/fill jvec with one's//") << endl;
  for (INTEGER i=1; i<=15; i++) jvec[i]=1;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i];
  cout << endl;

  /*
  cout << starbox("/print ivec, jvec, kvec pointer//") << endl;
  cout << "  " << ixptr(ivec) << "  " << ixptr(jvec) << "  "  << ixptr(kvec); 
  cout << endl;
  ivec.resize(25);

  cout << starbox("/same after ivec resize//") << endl;
  cout << "  " << ixptr(ivec) << "  " << ixptr(jvec) << "  " << ixptr(kvec); 
  cout << endl;
  */

  cout << starbox("/print ivec, jvec, kvec pointer//") << endl;
  cout <<"  "<< ivec.begin() <<"  "<< jvec.begin() <<"  "<< kvec.begin(); 
  cout << endl;
  ivec.resize(25);

  cout << starbox("/same after ivec resize//") << endl;
  cout <<"  "<< ivec.begin() <<"  "<< jvec.begin() <<"  "<< kvec.begin(); 
  cout << endl;

  cout << starbox("/ivec = jvec = kvec//") << endl;
  cout << endl;
  ivec = jvec = kvec;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i];
  cout << endl;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i];
  cout << endl;

  cout << starbox("/intvec of ones, resized to one of fives//") << endl;
  intvec lvec(5,1);
  for (INTEGER i=1; i<=lvec.size(); i++) cout << "  " << lvec[i];
  cout << endl;
  lvec.resize(6,5);
  for (INTEGER i=1; i<=lvec.size(); i++) cout << "  " << lvec[i];
  cout << endl;

  cout << starbox("/cout << ivec << jvec << kvec//") << endl;
  cout << ivec << jvec << kvec;

  cout << starbox("/ivec+=jvec, ivec-=jvec, ivec++, ivec--, ++ivec, --ivec//");
  cout << endl;
  ivec+=jvec;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;
  ivec-=jvec;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;
  ivec++;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;
  ivec--;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;
  ++ivec;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;
  --ivec;
  for (INTEGER i=1; i<=ivec.size(); i++) cout << "  " << ivec[i];
  cout << endl;

  cout << starbox("/ivec+jvec, ivec-jvec, +ivec, -ivec, 5*ivec, ivec*2//");
  cout << endl;
  kvec = ivec+jvec;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;
  kvec = ivec-jvec;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;
  kvec = +ivec;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;
  kvec = -ivec;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;
  kvec = 5*ivec;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;
  kvec = ivec*2;
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;

  cout << starbox("/fill(kvec), fill(kvec,5)//") << endl;
  fill(kvec);
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;
  fill(kvec,5);
  for (INTEGER i=1; i<=kvec.size(); i++) cout << "  " << kvec[i]; 
  cout << endl;

  cout << starbox("/ivec<ivec, ivec<=ivec, ivec>ivec, ivec>=ivec//") << endl;
  cout << (ivec<ivec) << (ivec<=ivec) << (ivec>ivec) << (ivec>=ivec) << endl;
  
  cout << starbox("/jvec, jvec.check(5)=1, jvec.check(5), jvec//") << endl;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i]; 
  cout << endl;
  jvec.check(5)=1;
  cout << jvec.check(5) << endl;
  for (INTEGER i=1; i<=jvec.size(); i++) cout << "  " << jvec[i]; 
  cout << endl;

  cout << starbox("/test intvec(const char* str) constructor//") <<'\n';
  cout << "ivec(\"\") = " << intvec("") << '\n'; 
  cout << "ivec(\"   \") = " << intvec("") << '\n'; 
  cout << "ivec(\"1:5\") = " << intvec("1:5") << '\n'; 
  cout << "ivec(\"1:5,7,-15,-100,60:50\") = " 
       << intvec("1:5,7,-15,-100,60:50") << '\n'; 
  cout << "ivec(\"1\") = " << intvec("1") << '\n'; 
  realmat A(5,5);
  for (INTEGER i=1; i<=25; i++) A[i]=i;
  cout << "A = " << A << '\n';
  cout << "A(\"1\",\"1\") =" << A("1","1"); 
  cout << "A(\"1\",\"\") =" << A("1",""); 

  cout << starbox("/check intvec_cmp//");
  intvec_cmp compare;
  intvec lhs = seq(1,15);
  intvec rhs = seq(1,15);
  cout << boolalpha << compare(lhs,rhs) << '\n';
  rhs++;
  cout << compare(lhs,rhs) << '\n';
  rhs--; rhs--;
  cout << compare(lhs,rhs) << '\n';

  cout << starbox("/check resize to null vector//");
  ivec.resize(0);
  cout << ivec;

  cout << starbox("/check push_back()//");
  intvec p;
  for (INTEGER i=1; i<=5; ++i) p.push_back(i);
  cout << p;
  p.resize(0);
  for (INTEGER i=1; i<=6; ++i) p.push_back(i);
  cout << p;
  for (INTEGER i=1; i<=6; ++i) p.push_back(i);
  cout << p;

  cout << starbox("/test reserve, capacity, erase//");
  intvec psave = p;
  cout << '\t' << "p.size() = " << p.size() << '\n';
  cout << '\t' << "p.capacity() = " << p.capacity() << '\n';
  cout << '\t' << p.reserve(p.capacity()+100) << '\n';
  cout << '\t' << "(p == psave) = " << (p == psave) << '\n';
  cout << '\t' << "p.size() = " << p.size() << '\n';
  cout << '\t' << "p.capacity() = " << p.capacity() << '\n';
  cout << '\t' << p.reserve(p.capacity()-100) << '\n';
  cout << '\t' << "(p == psave) = " << (p == psave) << '\n';
  cout << '\t' << "p.size() = " << p.size() << '\n';
  cout << '\t' << "p.capacity() = " << p.capacity() << '\n';
  cout << '\t' << p.reserve(p.size()) << '\n';
  cout << '\t' << "(p == psave) = " << (p == psave) << '\n';
  cout << '\t' << "p.size() = " << p.size() << '\n';
  cout << '\t' << "p.capacity() = " << p.capacity() << '\n';
  p.erase();
  cout << '\t' << "p.size() = " << p.size() << '\n';
  cout << '\t' << "p.capacity() = " << p.capacity() << '\n';

  cout << starbox("/check iterators//");
  ivec.resize(30,8);
  jvec.resize(30);
  intvec::iterator ivptr = ivec.begin();
  intvec::const_iterator jvptr = jvec.begin();
  while (ivptr != ivec.end()) *ivptr++ = *jvptr++;
  if (ivec == jvec) cout << "\n\t iterators work" << '\n';
  
  cout << starbox("/check tostring//");
  p = seq(1,15);
  cout << p.tostring() << '\n';
  cout << p.tostring('-') << '\n';
  cout << p.tostring(',',1) << '\n';
  cout << p.tostring(',',2) << '\n';
  cout << p.tostring(',',3) << '\n';
  cout << p.tostring('\0',0) << '\n';

  return 0;
}
