//This program test the class IntArray. #include #include "intarray.h" #include void new_line(istream& in_stream); //Discards all the input remaining on the current input line of in_stream. //Also discards the '\n' at the end of the line. //Precondition: in_stream has been connected to a file with a call to open. void wait(); void testcopy(); //Tests to see if the copy constructor is defined correctly. void test(IntArray a); //Used in testing to see if the copy constructor is defined correctly. int main() { int size = 10; IntArray a(size), b;//Note round parentheses. int i; cout << "Checking the default constructor.\n"; for (i = 0; i < size; i++) b[i] = i; for (i = 0; i < size; i++) cout << b[i]; cout << endl; cout << "Above line should be:\n" << "0123456789\n"; wait(); cout << "Checking get_size:\n"; cout << a.get_size() << " should = 10 \n"; wait(); /* cout << "The program should now end with an index out\n" << "of range error message.\n"; b[10] = 10; */ cout << "Checking the other constructor.\n"; for (i = 0; i < size; i++) a[i] = i; for (i = 0; i < size; i++) cout << a[i]; cout << endl; cout << "Above line should be:\n" << "0123456789\n"; wait(); /* cout << "The program should now end with an index out\n" << "of range error message.\n"; a[10] = 10; */ a.resize(12); cout << "Checking to see that values are not lost:\n"; for (i = 0; i < 10; i++) a[i] = i; for (i = 0; i < 10; i++) cout << a[i]; cout << endl; cout << "Above line should be:\n" << "0123456789\n"; wait(); cout << "Checking to see that array is resized:\n"; for (i = 0; i < 12; i++) a[i] = i; for (i = 0; i < 12; i++) cout << a[i]; cout << endl; cout << "Above line should be:\n" << "01234567891011\n"; wait(); /* cout << "Checking the overloaded operator <<:\n"; cout << a << "the end" << endl; cout << "Above line should be:\n" << "0 1 2 3 4 5 6 7 8 9 10 11 the end\n" << "NOTE: There should be no blank line after the array output.\n"; wait(); */ /* cout << "Checking the overloaded assignment operator:\n"; IntArray c(10), d; for (i = 0; i < size; i++) c[i] = i; d = c; for (i = 0; i < size; i++) cout << d[i]; cout << endl; cout << "Above line should be:\n" << "0123456789\n"; wait(); */ /* cout << "Checking the copy constructor:\n"; testcopy(); wait(); cout << "End of tests.\n" << "WARNING: Passing these tests does NOT\n" << "Guarantee that your definitions are correct!\n"; */ return 0; } //Uses iostream.h: void new_line(istream& in_stream) { char symbol; do { in_stream.get(symbol); } while (symbol != '\n'); } void wait() { cout << "Press return to continue to the next test.\n"; new_line(cin); } void testcopy() { IntArray a(10); int i; for(i = 0; i < 10; i++) a[i] = i; test(a); for(i = 0; i < 10; i++) cout << a[i]; cout << endl << "Above line should be:\n" << "0123456789\n"; } void test(IntArray a) { int i; for(i = 0; i < 10; i++) cout << a[i]; cout << endl << "Above line should be:\n" << "0123456789\n"; for(i = 0; i < 10; i++) a[i] = 7; }