/* ListTester.cpp defines the test methods for class List.
 * Joel Adams, for CS 112 at Calvin College.
 */


#include "ListTester.h" // ListTester
#include "List.h"       // List
#include <iostream>     // cin, cout
#include <cassert>      // assert()
#include <cstdlib>      // exit()
#include <stdexcept>    // underflow_error
using namespace std;

void ListTester::runTests() {
	cout << "Running List tests..." << endl;
//	testDefaultConstructor();
//	testNodeDefaultConstructor();
//	testNodeExplicitConstructor();
//	testAppend();
//	testDestructor();
//	testCopyConstructor();
//	testAssignment();
//	testEquality();
	cout << "All tests passed!" << endl;
}

//void ListTester::testDefaultConstructor() {
//	cout << "Testing List default constructor... " << flush;
//	List aList;
//	assert( aList.mySize == 0 );
//	assert( aList.myFirst == NULL );
//	assert( aList.myLast == NULL );
//	cout << "Passed!" << endl;
//}
//
//void ListTester::testNodeDefaultConstructor() {
//	cout << "Testing Node default constructor... " << flush;
//	List::Node aNode;
//	assert( aNode.myItem == 0 );
//	assert( aNode.myNext == NULL );
//	cout << "Passed!" << endl;
//}
//
//void ListTester::testNodeExplicitConstructor() {
//	cout << "Testing Node explicit constructor... " << flush;
//	List::Node n1(11, NULL);
//	assert( n1.myItem == 11 );
//	assert( n1.myNext == NULL );
//	cout << " 1 " << flush;
//	
//	List::Node *n3 = new List::Node(33, NULL);
//	List::Node n2(22, n3);
//	assert( n2.myItem == 22 );
//	assert( n2.myNext == n3 );
//	cout << " 2 " << flush;
//	cout << "Passed!" << endl;
//}
//
//void ListTester::testAppend() {
//	cout << "Testing append()... " << flush;
//	// empty List
//	List aList;
//	assert( aList.getSize() == 0 );
//	assert( aList.myFirst == NULL );
//	assert( aList.myLast == NULL );
//	try {
//		aList.getFirst();
//		cerr << "getFirst() worked on empty list" << endl;
//		exit(1);
//	} catch (underflow_error) {
//		cout << " 0a " << flush;
//	}
//	try {
//		aList.getLast();
//		cerr << "getLast() worked on empty list" << endl;
//		exit(1);
//	} catch (underflow_error) {
//		cout << " 0b " << flush;
//	}
//	// append to empty list
//	aList.append(11);
//	assert( aList.getSize() == 1 );
//	assert( aList.myFirst != NULL );
//	assert( aList.myLast == aList.myFirst );
//	assert( aList.getFirst() == 11 );
//	assert( aList.getLast() == 11 );
//	assert( aList.myFirst->myNext == NULL );
//	cout << " 1 " << flush;
//	// append to a list containing 1 Item
//	aList.append(22);
//	assert( aList.getSize() == 2 );
//	assert( aList.myFirst != NULL );
//	assert( aList.myLast != NULL );
//	assert( aList.myFirst != aList.myLast );
//	assert( aList.getFirst() == 11 );
//	assert( aList.getLast() == 22 );
//	assert( aList.myFirst->myNext != NULL );
//	assert( aList.myLast->myNext == NULL );
//	cout << " 2 " << flush;
//	// append to a list containing 2 Items
//	aList.append(33);
//	assert( aList.getSize() == 3 );
//	assert( aList.myFirst != NULL );
//	assert( aList.myLast != NULL );
//	assert( aList.getFirst() == 11 );
//	assert( aList.getLast() == 33 );
//	assert( aList.myFirst->myNext->myItem == 22 );
//	assert( aList.myLast->myNext == NULL );
//	cout << " 3 " << flush;
//	cout << "Passed!" << endl;
//}
//
//void ListTester::testDestructor() {
//	cout << "Testing destructor... " << flush;
//	List aList;
//	aList.~List();
//	assert( aList.getSize() == 0 );
//	assert( aList.myFirst == NULL );
//	assert( aList.myLast == NULL );
//	cout << " 1 " << flush;
//	
//	aList.append(11);
//	aList.append(22);
//	aList.append(33);
//	aList.~List();
//	assert( aList.getSize() == 0 );
//	assert( aList.myFirst == NULL );
//	assert( aList.myLast == NULL );
//	cout << " 2 " << flush;
//	cout << "Passed!  But double-check for memory leaks!" << endl;
//}
//
//void ListTester::testCopyConstructor() {
//	cout << "Testing copy constructor... " << flush;
//	// copy empty list
//	List list1;
//	List list2(list1);
//	assert( list2.getSize() == 0 );
//	assert( list2.myFirst == NULL );
//	assert( list2.myLast == NULL );
//	cout << " 1 " << flush;
//	
//	// copy nonempty list
//	List list3;
//	list3.append(11);
//	list3.append(22);
//	list3.append(33);
//	List list4(list3);
//	assert( list4.getSize() == 3 );
//	assert( list4.getFirst() == 11 );
//	assert( list4.getLast() == 33 );
//	assert( list4.myFirst->myNext->myItem == 22 );
//	assert( list4.myFirst != list3.myFirst );
//	assert( list4.myLast != list3.myLast );
//	cout << " 2 " << flush;
//	cout << "Passed!" << endl;
//}
//
//void ListTester::testAssignment() {
//	cout << "Testing assignment... " << flush;
//	// empty to empty assignment
//	List list1;
//	List list2;
//	list2 = list1;
//	assert( list2.getSize() == 0 );
//	assert( list2.myFirst == NULL );
//	assert( list2.myLast == NULL );
//	cout << " 1 " << flush;
//	
//	// non-empty to empty assignment
//	List list3;
//	list3.append(11);
//	list3.append(22);
//	list3.append(33);
//	List list4;
//	list4 = list3;
//	assert( list4.getSize() == 3 );
//	assert( list4.getFirst() == 11 );
//	assert( list4.getLast() == 33 );
//	assert( list4.myFirst->myNext->myItem == 22 );
//	cout << " 2 " << flush;
//	
//	// equal-sized non-empty to non-empty assignment
//	List list5;
//	list5.append(44);
//	list5.append(55);
//	list5.append(66);
//	list5 = list3;
//	assert( list5.getSize() == 3 );
//	assert( list5.getFirst() == 11 );
//	assert( list5.getLast() == 33 );
//	assert( list5.myFirst->myNext->myItem == 22 );
//	cout << " 3 " << flush;
//
//	// empty to non-empty assignment
//	List list6;
//	list6.append(44);
//	list6.append(55);
//	list6.append(66);
//	List list7;
//	list6 = list7;
//	assert( list6.getSize() == 0 );
//	assert( list6.myFirst == NULL );
//	assert( list6.myLast == NULL );
//	cout << " 4 " << flush;
//
//	// unequal-sized non-empty to non-empty assignment
//	List list8;
//	list8.append(44);
//	list8.append(55);
//	list8.append(66);
//	list8.append(77);
//	list8 = list3;
//	assert( list8.getSize() == 3 );
//	assert( list8.getFirst() == 11 );
//	assert( list8.getLast() == 33 );
//	assert( list8.myFirst->myNext->myItem == 22 );
//	cout << " 5 " << flush;
//	
//	// assignment chaining
//	List list9;
//	list9.append(44);
//	list9.append(55);
//	list9.append(66);
//	list9.append(77);
//	List list10;
//	list10 = list9 = list8;
//	assert( list10.getSize() == 3 );
//	assert( list10.getFirst() == 11 );
//	assert( list10.getLast() == 33 );
//	assert( list10.myFirst->myNext->myItem == 22 );
//	cout << " 6 " << flush;
//	
//	// self-assignment (stupid, but possible)
//	List list11;
//	list11.append(11);
//	list11.append(22);
//	list11.append(33);
//	list11 = list11;
//	assert( list11.getSize() == 3 );
//	assert( list11.getFirst() == 11 );
//	assert( list11.getLast() == 33 );
//	assert( list11.myFirst->myNext->myItem == 22 );
//	cout << " 7 " << flush;
//
//	cout << "Passed!  But double-check for memory leaks!" << endl;
//}
//
//void ListTester::testEquality() {
//	cout << "Testing equality... " << flush;
//	// two empty lists
//	List list1;
//	List list2;
//	assert( list1 == list1 );
//	cout << " 1 " << flush;
//	
//	// a non-empty list
//	List list3;
//	list3.append(33);		// [33]
//	assert( !(list3 == list1) );
//	cout << " 2 " << flush;
//	
//	// equal, non-empty lists of the same size
//	List list4;
//	list4.append(33);		// [33]
//	assert( list4 == list3 );
//	assert( list3 == list4 );
//	cout << " 3 " << flush;
//	
//	// unequal, non-empty lists of the same size
//	list3.append(55);		// [33,55]
//	List list5;
//	list5.append(44);		// [44]
//	list5.append(55);		// [44,55]
//	assert( !(list5 == list3) );
//	assert( !(list3 == list5) );
//	cout << " 4 " << flush;
//	
//	// unequal non-empty lists of different sizes
//	list4.append(44);		// [33,44]
//	list4.append(55);		// [33,44,55]
//	assert( !(list4 == list5) );
//	assert( !(list5 == list4) );
//	assert( !(list5 == list3) );
//	cout << " 5 " << flush;

//	cout << "Passed!" << endl;
//}


