#include <iostream>
#include <string>
#include "bigint.h"

/*
To use, create a project with this as the source file.  Add the following files in the project (if applicable):
	BigInt.cpp
	BigInt.h

This basic test program was written by and is copyrighted © 2003 by Sean Colombo and Sinisoft.
It is for free-release with the BigInt class.
*/

#if defined(LINUX)
#define CLS "clear"
#elif defined(WIN32)
#define CLS "CLS"
#else
#define CLS "clear" // this is fine for most OSes, if yours is different you may need to change this
#endif

using namespace std; // needed because of use of string class

void doPause();

int main(){
	string filler;
	BigInt testLeft;
	BigInt testRight(100); // only works with limited sizes in parentheses, see below for large numbers
	BigInt testAns;

	cout<<"**HELLO AND WELCOME TO THE BIGINT TEST DRIVER PROGRAM**"<<endl<<endl;

	cout<<"Constructor test (should be 100): "<<testRight<<endl;

	cout<<"Comparison operator test:"<<endl;
	cout<<"(statement) should-be: actual-returned"<<endl;
	testLeft=5;
	testRight=2;
	cout<<"(5 == 2) 0: "<<(testLeft==testRight)<<endl;
	testLeft=2;
	cout<<"(2 == 2) 1: "<<(testLeft==testRight)<<endl;
	testLeft=5;
	cout<<"(5 != 2) 1: "<<(testLeft!=testRight)<<endl;
	testLeft=2;
	cout<<"(2 != 2) 0: "<<(testLeft!=testRight)<<endl;
	testLeft=3;
	testRight=7;
	cout<<"(3 <= 7) 1: "<<(testLeft<=testRight)<<endl;
	testLeft=7;
	cout<<"(7 <= 7) 1: "<<(testLeft<=testRight)<<endl;
	testLeft=9;
	cout<<"(9 <= 7) 0: "<<(testLeft<=testRight)<<endl;
	testLeft=3;
	cout<<"(3 >= 7) 0: "<<(testLeft>=testRight)<<endl;
	testLeft=7;
	cout<<"(7 >= 7) 1: "<<(testLeft>=testRight)<<endl;
	testLeft=9;
	cout<<"(9 >= 7) 1: "<<(testLeft>=testRight)<<endl;
	testLeft=2;
	testRight=5;
	cout<<"(2 < 5)  1: "<<(testLeft<testRight)<<endl;
	testLeft=5;
	cout<<"(5 < 5)  0: "<<(testLeft<testRight)<<endl;
	testLeft=7;
	cout<<"(7 < 5)  0: "<<(testLeft<testRight)<<endl;
	testLeft=2;
	cout<<"(2 > 5)  0: "<<(testLeft>testRight)<<endl;
	testLeft=5;
	cout<<"(5 > 5)  0: "<<(testLeft>testRight)<<endl;
	testLeft=7;
	cout<<"(7 > 5)  1: "<<(testLeft>testRight)<<endl;

	cout<<endl<<"More to come."<<endl;
	doPause();
	system(CLS);

	filler = "123456789123456789123456789123456789123456789123456789";
	testLeft = filler;// strings can be assigned to BigInts (they are converted automatically)

	testRight = (string)"123456789123456789123456789123456789123456789123456700"; // best for large numbers
	testAns = testLeft-testRight;
	cout<<"Subtraction test (should be 89): "<<testAns<<endl;
	
	testLeft = (string)"12";
	testRight = 5; // this works because it's in the range of ints
	testAns = testLeft+testRight;
	cout<<"Addition test (should be 17): "<<testAns<<endl;
	testAns += 2;
	cout<<"Addition test (should be 19): "<<testAns<<endl;

	testLeft=3;
	testRight=5;
	testAns = (testLeft * testRight);
	cout<<"Multiplication test (should be 15): "<<testAns<<endl;
	testAns *=2;
	cout<<"Multiplication test (should be 30): "<<testAns<<endl;

	testLeft=21;
	testRight=7;
	testAns = testLeft/testRight;
	cout<<"Division test (should be 3): "<<testAns<<endl;
	testLeft=23;
	testAns = testLeft/testRight;
	cout<<"Division test (should be 3): "<<testAns<<endl;

	testLeft=21;
	testRight=7;
	testAns = testLeft%testRight;
	cout<<"Modular division test (should be 0): "<<testAns<<endl;
	testLeft=23;
	testAns = testLeft%testRight;
	cout<<"Modular division test (should be 2): "<<testAns<<endl;

	testLeft = 2;
	testRight = 7;
	testAns = testLeft^testRight;
	cout<<"Exponentiation test (should be 128): "<<testAns<<endl;
	testAns = ((BigInt)2^(BigInt)10);//MUST cast to BigInt
	cout<<"Exponentiation test (should be 1024): "<<testAns<<endl;

	testAns = 25;
	testAns = testAns.sqrt();
	cout<<"Square Root test (should be 5): "<<testAns<<endl;
	testAns = 27;
	testAns = testAns.sqrt();
	cout<<"Square Root test (should be 5): "<<testAns<<endl;

	testLeft=12321;
	testAns = testLeft.digitalRoot();
	cout<<"Digital Root test (should be 9): "<<testAns<<endl;
	testLeft=12345;
	testAns = testLeft.digitalRoot();
	cout<<"Digital Root test (should be 6): "<<testAns<<endl;

	cout<<endl<<"More to come."<<endl;
	doPause();
	system(CLS);

	// isPrime is used in nextPrime so we shall just generate the first several primes
	cout<<"isPrime() and nextPrime() test:"<<endl;
	testAns=0;
	for(int cnt=0;cnt<19;cnt++){
		testAns = testAns.nextPrime();
		cout<<testAns<<endl;
		testAns+=1;
	}

	cout<<endl<<"Testing complete."<<endl;
	doPause();

	return 0;
}

void doPause(){
	cout<<"Press any key to continue..."<<endl;
	cin.get();
}
