/************************************************************************* * Memorial University of Newfoundland * Faculty of Engineering and Applied Sciences * Engineering 3891 : Advanced Programming * * Assignment 5 Test Code * * Author: Daniel Mastropietro * Student ID: 9419268 Date: 10.16.00 *************************************************************************/ #include "assign5.h" #include #include #include using namespace std; void main () { myComplex x,y; char choice; char operation; char pause; int i; bool result = true; cout <<"Engr 3891 Assignment 5 Test Code\n\n"; while (choice != '5') { cout <<"Kindly choose one of the following options:\n" <<"1) Push a number onto the stack\n" <<"2) Pop a number off of the stack\n" <<"3) Do an operation\n" <<"4) Run tests\n" <<"5) Exit the Program\n" <<"Choice : "; cin >> choice; cout << "\n\n"; switch (choice) { case '1': cout <<"Please enter the number to be put into the stack\n" <<"Real Part : "; cin >> x.re; cout <<"Imaginary Part : "; cin >> x.im; cout <<"The function Push returned ---> " << (push(x) ? "TRUE" : "FALSE") <<"\n\n"; break; case '2': if ( pop(x) ) { cout <<"The number retrieved is " <=0 ? " + " : " - ") << fabs(x.im) <<"j\n\n"; } else cout <<"No number can be retrieved\n\n"; break; case '3': cout <<"What operation would you like to do? "; cin >>operation; if ( oper (operation) ) { cout <<"\n The result of the operation was "; pop(x); cout <=0 ? " + " : " - ") << fabs(x.im) <<"j\n\n"; } else cout <<"\tThe operation was unsuccesful\n\n"; break; case '4': while (pop(x)) {;} x.re = 2.5; x.im = -1.5; cout <<"Test 1: Push a number onto the queue .................." <<( push (x) ? "PASSED" : "FAILED") <<'\n' <<"Test 2: Pop a number fom the queue ...................."; if (pop(x)) cout << "PASSED\n"; else cout <<"FAILED\n"; cout <<"Test 3: Filling up the stack..........................."; for( i=0;i<15 && push(x);i++) { x.re=rand();x.im=rand(); } if ( i !=10) cout <<"FAILED\n\tYour program only took " <=0 && result;i--){pop(x);if(x.re == i+1 && x.im == i+1) result=true; else result = false;} if (result) cout <<"PASSED\n"; else cout <<"FAILED\n"; cout <<"Test 8: Addition......................................."; x.re=4.5; y.re=-7.5; x.im=-3.5; y.im=6.5; push(x); push(y); if ( oper('+') && pop(x) ) if (x.re == -3.0 && x.im == 3.0) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou said (4.5-3.5j) + (-7.5+6.5j) = " <=0 ? " + " : " - ") << fabs(x.im) <<"j\n"; else cout <<"FAILED\n\tYour program either will not let me do the operation, or won't give me the result.\n"; cout <<"Test 9: Subtraction:..................................."; x.re=4.5; y.re=-7.5; x.im=-3.5; y.im=6.5; push(x); push(y); if ( oper('-') && pop(x) ) if (x.re == 12.0 && x.im == -10.0) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou said (4.5-3.5j) - (-7.5+6.5j) = " <=0 ? " + " : " - ") << fabs(x.im) <<"j\n"; else cout <<"FAILED\n\tYour program either will not let me do the operation, or won't give me the result.\n"; cout <<"Test 10: Multiplication:..............................."; x.re=4.5; y.re=-7.5; x.im=-3.5; y.im=6.5; push(x); push(y); if ( oper('*') && pop(x) ) if (x.re == -11.0 && x.im == 55.5) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou said (4.5-3.5j) * (-7.5+6.5j) = " <=0 ? " + " : " - ") << fabs(x.im) <<"j\n"; else cout <<"FAILED\n\tYour program either will not let me do the operation, or won't give me the result.\n"; cout <<"Test 11: Division:....................................."; x.re=6; y.re=0; x.im=-9; y.im=3; push(x); push(y); if ( oper('/') && pop(x) ) if (x.re == -3 && x.im == -2) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou said (6-9j) / (0+3j) = " <=0 ? " + " : " - ") << fabs(x.im) <<"j\n"; else cout <<"FAILED\n\tYour program either will not let me do the operation, or won't give me the result.\n"; cout <<"Test 12: Division by Zero:............................."; x.re=-2.5; y.re=0; x.im=3.5; y.im=0; push(x); push(y); if ( !oper('/') ) if (pop (x) && x.re == 0 && x.im == 0 && pop(y) && y.re == -2.5 && y.im == 3.5) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou returned false, but changed the numbers in your stack\n"; else cout <<"FAILED\n\tYou gave no error for division by zero\n"; cout <<"Test 13: Not enough numbers for operation.............."; while (pop(x)); x.re = 3.5; x.im = -4.5; push(x); if (!oper ('*') ) if (pop (x) && x.re == 3.5 && x.im == -4.5) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou returned false, but changed the numbers in your stack\n"; else cout <<"FAILED\n\tYou allowed me to do the operation without enough numbers in the stack\n"; cout <<"Test 14: Invalid Operation............................."; pop(x); pop(x); if (!oper('D')) cout <<"PASSED\n"; else cout <<"FAILED\n\tYou did not return false when I entered an invalid operation\n"; cout <<"\nPlease hit to continue"; cin.get(pause); cin.get(pause); cout <<'\n'; break; case '5': break; default: cout <<"Invalid number\n\n"; break; } } return; }