00001 #include <iostream>
00002 #include <string>
00003 #include "testObjects.h"
00004 #include "../common/filereader.h"
00005 using namespace std;
00006
00007 Natural maintests(Natural argc, char **argv)
00008 {
00009 const ShortNatural TESTNAME_LEN=30;
00010
00011
00012 if (FileReader::setdatadir(argv[0]) == false) {
00013 cout << "could not set data dir, some tests may fail" << endl;
00014 }
00015
00016 cout<<"\n**************************************"<<endl;
00017 cout<<"****** Objects Testing Module ******"<<endl;
00018 cout<<"**************************************\n"<<endl;
00019
00020 bool testpass = true;
00021 bool playagain=true;
00022 string choice;
00023 Natural choiceNAt=0;
00024
00025 struct tests {
00026 char testname[TESTNAME_LEN];
00027 bool (*testfunction)();
00028 };
00029
00030 while (playagain) {
00031 choiceNAt=0;
00032 playagain=false;
00033 testpass=true;
00034
00035 tests testarray[] = {
00036 {"filereader", mainfilereader},
00037 {"interpolator", maininterpolator},
00038 {"matrix", mainmatrix},
00039 {"date", maindate},
00040 {"yieldcurve", mainyieldcurve},
00041 {"volsurface", mainvolsurface},
00042 {"creditcurve", maincreditcurve},
00043 {"blackscholes", mainoption},
00044 {"optionstrategy", mainoptionstrategy},
00045 {"montecarlo", mainmontecarlo},
00046 {"asset", mainasset},
00047 {"rainbowoptions", mainrainbowoptions},
00048 {"varianceswaps",mainvarianceswap},
00049 {"bond", mainbond},
00050 {"binomialtree", mainbinomialtree},
00051 {"convertiblebond", mainconvertiblebond},
00052 {"IRVanillaSwap", mainIRVanillaSwap}
00053 };
00054 Natural maxtest = sizeof(testarray)/sizeof(tests);
00055
00056 for (ShortNatural i = 0; i < maxtest; i++) {
00057 cout << " Press " << i + 1<< " for " << testarray[i].testname << endl;
00058 }
00059 cout<<"* Press "<<maxtest+1<<" for all tests (might be long)"<<endl;
00060 cout <<"* Press something else than a number between 1 and "<<maxtest+1<<" to end program"<<endl;
00061
00062 cin >> choice;
00063 choiceNAt=atoi(choice.c_str());
00064 if(choiceNAt<=maxtest && choiceNAt>0) {
00065 testpass &= testarray[choiceNAt-1].testfunction();
00066 if (testpass) {
00067 cout << "\n\n***** all tests passed" << endl;
00068 } else {
00069 cout << "\n\n***** some tests failed" << endl;
00070 }
00071 Natural test=0;
00072 cout << "\nType 1 + enter key to test again or any other key to end the test module" << endl;
00073 cin >> test;
00074 if (test==1) playagain=true;
00075 }
00076 else {
00077 if(choiceNAt==maxtest+1){
00078 for (ShortNatural i = 0; i < maxtest; i++) {
00079 testpass &= testarray[i].testfunction();
00080 }
00081 if (testpass) {
00082 cout << "\n\n***** all tests passed" << endl;
00083 } else {
00084 cout << "\n\n***** some tests failed" << endl;
00085 }
00086 Natural test=0;
00087 cout << "\nType 1 + enter key to test again or any other key to end the test module" << endl;
00088 cin >> test;
00089 if (test==1) playagain=true;
00090 }
00091 }
00092 }
00093
00094 if (testpass) {
00095 return 1;
00096 } else {
00097 return 0;
00098 }
00099 }