// testInstructor.cc    P. Conrad for CISC220, 06J
// test of Instructor_C derived class


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

#include "runTests.h"

#include "person.h"
#include "instructor.h"

int main(void)
{

  RunTests_C test;


  Instructor_C x("Phill","Conrad",123,"CIS");

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getDept(),"CIS");

  // now test the copy constructor and overloaded assignment operator

  Instructor_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.getDept(),"CIS");

  // 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.setDept("ECE");

  test.assertEquals(y.getFname(),"Fred");
  test.assertEquals(y.getLname(),"Flintstone");
  test.assertEquals(y.getId(),456);
  test.assertEquals(y.getDept(),"ECE");

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getDept(),"CIS");

  Instructor_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.getDept(),"CIS");

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getDept(),"CIS");

  // test the overloaded = sign

  Instructor_C a("Adam","Smith",789,"ANTH");
  Instructor_C b("Betty","Davis",321,"BIOL");

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

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

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

    // 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.getDept(),"BIOL");
  
  test.assertEquals(b.getFname(),"Adam");
  test.assertEquals(b.getLname(),"Smith");
  test.assertEquals(b.getId(),789);
  test.assertEquals(b.getDept(),"ANTH");

  // 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.getDept(),"BIOL");

  a = b = x;

  test.assertEquals(x.getFname(),"Phill");
  test.assertEquals(x.getLname(),"Conrad");
  test.assertEquals(x.getId(),123);
  test.assertEquals(x.getDept(),"CIS");

  test.assertEquals(a.getFname(),"Phill");
  test.assertEquals(a.getLname(),"Conrad");
  test.assertEquals(a.getId(),123);
  test.assertEquals(a.getDept(),"CIS");

  test.assertEquals(b.getFname(),"Phill");
  test.assertEquals(b.getLname(),"Conrad");
  test.assertEquals(b.getId(),123);
  test.assertEquals(b.getDept(),"CIS");

  // finish the test by printing a report

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



