// binTreeDotTest.cc    TDD for simple binary tree class
// P. Conrad for CISC220, 06J

#include "runTests.h"
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

// Now also do #include <string> and #include <sstream>
// This allows us to write to a string (C++ style string) as if it were 
// a file.  That way, we can test our print functions

#include <string>
using std::string;

#include <sstream>
using std::ostringstream;

#include "bintree.h"

void printHeader(const char * const file, int line)
{
  cout << "\n=== Tests from " << file << " at line " << line << "===" << endl;
}

int main(void)
{

  RunTests_C test;

  printHeader(__FILE__,__LINE__);

  BinTree t1(1);

  BinTree t2(1,
	     new BinTree(2),
	     new BinTree(3));



  
  {
    printHeader(__FILE__,__LINE__);
    ostringstream tprint;
    t1.dotPrint(tprint);
    test.assertEquals
      (tprint.str(),
       "digraph G { node [shape=circle] 1 \n"
       "node [shape=plaintext label=\"null\"]\n"
       "1->_1l "
       "1->_1r "
       "}\n");
  }

  {
    printHeader(__FILE__,__LINE__);
    ostringstream tprint;
    t2.dotPrint(tprint);
    test.assertEquals
      (tprint.str(),
       "digraph G { node [shape=circle] 1 2 3 \n"
       "node [shape=plaintext label=\"null\"]\n"
       "1->2 "
       "2->_2l "
       "2->_2r "
       "1->3 "
       "3->_3l "
       "3->_3r "
       "}\n");
  }

  BinTree t4(1,
	     new BinTree(2, NULL, new BinTree(3) ),
	     new BinTree(4, new BinTree(5), NULL));

  {
    printHeader(__FILE__,__LINE__);
    ostringstream tprint;
    t4.dotPrint(tprint);
    test.assertEquals
      (tprint.str(),
       "digraph G { node [shape=circle] 1 2 3 4 5 \n"
       "node [shape=plaintext label=\"null\"]\n"
       "1->2 "
       "2->_2l "
       "2->3 "
       "3->_3l "
       "3->_3r "
       "1->4 "
       "4->5 "
       "5->_5l "
       "5->_5r "
       "4->_4r "
       "}\n");
  }
  
  test.print();
  test.finish();

}





