// testStudent.cc    P. Conrad for CISC220, 06J
// test of Student_C derived class


#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

#include "runTests.h"

#include "person.h"
#include "student.h"

int main(void)
{

  RunTests_C test;


  Student_C x("Phill","Conrad",123,"CS",3.79);

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getMajor(),"CS");
  test.assertEquals(x.getGPA(),3.79);

  // now test the copy constructor and overloaded assignment operator

  Student_C y(x); // tests the copy constructor's copying
  test.assertEquals(y.getFname(),"Phill");
  test.assertEquals(y.getLname(),"Conrad");
  test.assertEquals(y.getId(),123);
  test.assertEquals(y.getMajor(),"CS");
  test.assertEquals(y.getGPA(),3.79);

  // now test the independence of x and y--i.e. make sure
  // we did a deep copy and not a shallow one

  y.setFname("Fred");
  y.setLname("Flintstone");
  y.setId(456);
  y.setMajor("CPEG");
  y.setGPA(2.53);

  test.assertEquals(y.getFname(),"Fred");
  test.assertEquals(y.getLname(),"Flintstone");
  test.assertEquals(y.getId(),456);
  test.assertEquals(y.getMajor(),"CPEG");
  test.assertEquals(y.getGPA(),2.53);

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getMajor(),"CS");
  test.assertEquals(x.getGPA(),3.79);

  Student_C z = x; // does it use copy constructor or overloaded =?

  test.assertEquals(z.getFname(),"Phill");
  test.assertEquals(z.getLname(),"Conrad");
  test.assertEquals(z.getId(),123);
  test.assertEquals(z.getMajor(),"CS");
  test.assertEquals(z.getGPA(),3.79);

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getMajor(),"CS");
  test.assertEquals(x.getGPA(),3.79);

  // test the overloaded = sign

  Student_C a("Adam","Smith",789,"ANTH",3.42);
  Student_C b("Betty","Davis",321,"BIOL",3.59);

  {
    // go into an inner block to test the destructor

    Student_C temp("Temp","Temp",999,"None",0.00);
    
    temp = a;
    a = b;
    b = temp;

    test.assertEquals(temp.getFname(),"Adam");
    test.assertEquals(temp.getLname(),"Smith");
    test.assertEquals(temp.getId(),789);
    test.assertEquals(temp.getMajor(),"ANTH");
    test.assertEquals(temp.getGPA(),3.42);

    // this tests the destructor, since it will be called
    // at this point for the temp object
    // at this point, the most we can do is hope it doesn't seg fault
    // later we'll see better ways to test a destructor, and check
    // for memory leaks
  }
  
  test.assertEquals(a.getFname(),"Betty");
  test.assertEquals(a.getLname(),"Davis");
  test.assertEquals(a.getId(),321);
  test.assertEquals(a.getMajor(),"BIOL");
  test.assertEquals(a.getGPA(),3.59);
  
  test.assertEquals(b.getFname(),"Adam");
  test.assertEquals(b.getLname(),"Smith");
  test.assertEquals(b.getId(),789);
  test.assertEquals(b.getMajor(),"ANTH");
  test.assertEquals(b.getGPA(),3.42);

  // finally, test chaining and self assignment

  a = a;

  test.assertEquals(a.getFname(),"Betty");
  test.assertEquals(a.getLname(),"Davis");
  test.assertEquals(a.getId(),321);
  test.assertEquals(a.getMajor(),"BIOL");
  test.assertEquals(a.getGPA(),3.59);

  a = b = x;

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getMajor(),"CS");
  test.assertEquals(x.getGPA(),3.79);

  test.assertEquals(a.getFname(),"Phill");
  test.assertEquals(a.getLname(),"Conrad");
  test.assertEquals(a.getId(),123);
  test.assertEquals(a.getMajor(),"CS");
  test.assertEquals(x.getGPA(),3.79);

  test.assertEquals(b.getFname(),"Phill");
  test.assertEquals(b.getLname(),"Conrad");
  test.assertEquals(b.getId(),123);
  test.assertEquals(b.getMajor(),"CS");
  test.assertEquals(b.getGPA(),3.79);

  // finish the test by printing a report

  test.print(cerr);
  test.finish();
}



