// baseballReadFileTest.cc   P. Conrad for CISC220, 06J
// try reading one line of the Master.csv file

// See license and copyright statement at bottom of file


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

#include "runTests.h"

#include "baseballMaster.h"

int main(int argc, char *argv[])
{

  if (argc!=2)
    {
      cerr << "Usage: " << argv[0] << " filename " << endl;
      exit(1);
    }
  
  ifstream inf(argv[1],std::ios::in);

  if (!inf)
    {
      cerr << "Error: can't open " << argv[1] << endl;
      exit(2);
    }
  
  const int bufsize = 2048;
  char buffer[bufsize];

  inf.getline(buffer,bufsize); // skip over headings
  inf.getline(buffer,bufsize); // read first line of real data

  char *inputLine1 = new char [strlen(buffer) + 1];
  strcpy(inputLine1, buffer);
  
  RunTests_C test;

  
    
  BaseballMaster_C player1(inputLine1);

  test.assertEquals(player1.getLahmanID(),1);

  test.assertEquals(player1.getPlayerID(),"aaronha01");
  test.assertEquals(player1.getManagerID(),"");
  test.assertEquals(player1.getHofID(),"aaronha01h");

  test.assertEquals(player1.getBirth()->getDate().getYear(),1934);
  test.assertEquals(player1.getBirth()->getDate().getMonth(),2);
  test.assertEquals(player1.getBirth()->getDate().getDay(),5);
  test.assertEquals(player1.getBirth()->getCountry(),"USA");
  test.assertEquals(player1.getBirth()->getState(),"AL");
  test.assertEquals(player1.getBirth()->getCity(),"Mobile");

  test.assertEquals((int) player1.getDeath(),0);
  test.assertEquals(player1.getNameFirst(),"Hank");
  test.assertEquals(player1.getNameLast(),"Aaron");
  test.assertEquals(player1.getNameNote(),"");
  test.assertEquals(player1.getNameGiven(),"Henry Louis");
  test.assertEquals(player1.getNameNick(),"Hammer,Hammerin' Hank,Bad Henry");

  test.assertEquals(player1.getWeight(),180);
  test.assertEquals(player1.getHeight(),72);\

  test.assertEquals(player1.getBats(),'R');
  test.assertEquals(player1.getThrows(),'R');

  test.assertEquals(player1.getDebut(),Date_C("4/13/1954"));
  test.assertEquals(player1.getFinalGame(),Date_C("10/3/1976"));

  test.assertEquals(player1.getCollege(),"");
  test.assertEquals(player1.getLahman40ID(),"aaronha01");
  test.assertEquals(player1.getLahman45ID(),"aaronha01");
  test.assertEquals(player1.getRetroID(),"aaroh101");
  test.assertEquals(player1.getHoltzID(),"aaronha01");


  std::cerr << "player1.getBbrefID()=" << std::endl
	    << "<" << player1.getBbrefID() << ">" <<  std::endl;    

  test.assertEquals(player1.getBbrefID(),"aaronha01");

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

  delete [] inputLine1; // recycle memory on heap
  return 0;

}



// COPYRIGHT NOTICE:

// This code corresponds to the data layout of the Lahmann Database,
// which is copyrighted by Sean Lahmann.  The data and formats here
// are used by special permission of Sean Lahmann, granted to Phill 
// Conrad for use in Computer Science courses at the University of 
// Delaware.  You must obtain permission from Sean Lahmann to use this
// data and/or data format for any other purpose.  For more details,
// visit www.baseball1.com

