// a testmain routine to check the behavior of the PointPairSet class
// for the grading of project 2
#include <iostream>

#include "PointPairSet.h"
#include "PointPair.h"
#include "Point.h"

// students should download testmain.cpp and compile with all the files
// in the smae directory
//students' compile line: g++ -O6 -Wall -g -pedantic testmain.cpp Point.cpp PointPair.cpp PointPairSet.cpp

// compile line: g++ -O6 -Wall -g -pedantic -I/home/scratch4/ahawkins/class/project2/ ../testmain.cpp Point.cpp PointPair.cpp PointPairSet.cpp



int main()
{



// Construct objects to manipulate

    // Verify all Point constructors and assignments
    Point x(1,1);
    Point y(2,2);
    Point z(3,3);
    Point origin;
    Point a(origin);
    Point inPoint;
    
    PointPair inPair;

    // Verify input overloading
    cout << "inPoint = x y"<< endl;
    cin >> inPoint;
    cout << "inPair = (x1 y1) (x2 y2)" << endl;
    cin >> inPair;

      // Verify all PointPair constructors and assignments
    Point c = inPoint;
    PointPair defaultPP;
    PointPair ac(a,c);
    PointPair ac2(ac);
    PointPair xx(x,x);
    PointPair yy(y,y);
    PointPair zz(z,z);
    
    PointPairSet pset;
    PointPairSet* ptr_set = new PointPairSet();

    cout << "Adding xx, yy, zz, to pset" << endl;
    pset.add(xx);
    pset.add(yy);
    pset.add(zz);
    cout << "Adding zz, xx, yy to *ptr_set" << endl;
    ptr_set->add(zz);
    ptr_set->add(yy);
    ptr_set->add(xx);
    cout << "Is pset == *ptr_set? ";
    if (pset == (*ptr_set))
        cout << "Yes" << endl<<endl;
    else
        cout << "No" << endl<<endl;

    cout << "Clean those sets" << endl;
    pset.clean();
    ptr_set->clean();
    cout << pset;
    cout << *ptr_set;
    
     cout << "numElements in pset = " << pset.numElements() << endl;
     cout << "Is pset empty?  " << pset.isEmpty() << endl;
     cout << "Is pset == *ptr_set?  "<< (pset == (*ptr_set)) << endl << endl;

      cout <<"adding ac to pset" << endl;
      pset.add(ac);
      cout << "Is pset empty?  " << pset.isEmpty() << endl;
      cout << "Is pset == *ptr_set?  "<< (pset == (*ptr_set)) << endl;
      cout << "numElements = " << pset.numElements() << endl << endl;

      cout <<"adding defaultPP = "<< defaultPP << endl;
      pset.add(defaultPP);
      cout << "numElements in pset = " << pset.numElements() << endl;
      cout <<"adding ac2 = "<< ac2 << endl;
      pset.add(ac2);
      cout << "numElements in pset = " << pset.numElements() << endl;
      cout <<"adding inPair = "<< inPair << endl;
      pset.add(inPair);
      cout << "numElements in pset = " << pset.numElements() << endl<<endl;

      cout << "Copy pset into pset2" << endl;
      PointPairSet pset2(pset);
      cout << "numElements in pset2 = " << pset2.numElements() << endl;
      cout << "evaluate pset2 == pset " << (pset2 == pset) << endl;
      cout << "evaluate pset2 != pset " << (pset2 != pset) << endl;
      cout << "Pset2 has pointpair ac2? " << (pset2.has(ac2)) << endl;
      cout << "Remove ac2 from pset2 " << pset2.remove(ac2) << endl;
      cout << "numElements in pset2 = " << pset2.numElements() << endl;
      cout << "Pset2 has pointpair ac2? " << (pset2.has(ac2)) << endl;
      
      cout <<"trying to add ac to pset2" << endl;
      pset.add(ac);
      cout << "numElements = " << pset.numElements() << endl <<endl;
      
      cout <<"forcing ac into pset" << endl;
      pset.force(ac);
      cout << "numElements = " << pset.numElements() << endl << endl;

      cout << "Testing indexing by iterating through pset " << endl;

      for(int i = 0; i < 8; i++)
      {
          if(i == (int)pset.numElements())
              cout << "Attempting to reference out of index range..." << endl;
          inPair = pset[i];
          cout << inPair << endl;
      }

      
    return 0;
}

// Sample Output Instance

//  inPoint = x y
//  1 1
//  inPair = (x1 y1) (x2 y2)
//  (4 4) (5 5)
//  Adding xx, yy, zz, to pset
//  Adding zz, xx, yy to *ptr_set
//  Is pset == *ptr_set? Yes

//  Clean those sets

//  This PointPairSet Contains: 
//  Zero PointPair


//  This PointPairSet Contains: 
//  Zero PointPair

//  numElements in pset = 0
//  Is pset empty?  1
//  Is pset == *ptr_set?  1

//  adding ac to pset
//  Is pset empty?  0
//  Is pset == *ptr_set?  0
//  numElements = 1

//  adding defaultPP = (0 0)  (1 1)
//  numElements in pset = 1
//  adding ac2 = (0 0)  (1 1)
//  numElements in pset = 1
//  adding inPair = (4 4)  (5 5)
//  numElements in pset = 2

//  Copy pset into pset2
//  numElements in pset2 = 2
//  evaluate pset2 == pset 1
//  evaluate pset2 != pset 0
//  Pset2 has pointpair ac2? 1
//  Remove ac2 from pset2 0
//  numElements in pset2 = 1
//  Pset2 has pointpair ac2? 0
//  trying to add ac to pset2
//  numElements = 2

//  forcing ac into pset
//  numElements = 3

//  Testing indexing by iterating through pset 
//  (0 0)  (1 1)
//  (4 4)  (5 5)
//  (0 0)  (1 1)
//  Attempting to reference out of index range...
//  PointPairSet Fatal: index exceeds total number of elements

