using namespace std; #include #include "../Array.h" #include "../Array.cc" #include "test_utilities.h" int main(int argc, char *argv[]) { test_init(20, argv[0]); // test basic operations Array A(-2); test(1, A.size() == 0, "new Array should have size() == 0"); test(1, A[0] == -2, "Array declared with default initializer doesn't initialize"); A[0] = 3; test(1, A[0] == 3, "assignment to Array operator[] fails"); A[2] = 0; test(1, A.size() == 3, "Array size() returns incorrect size"); // copy constructor, some const correctness const Array & B(A); const Array BB(A); Array C; test(1, BB.size() == 3, "Array copy constructor fails? (wrong size)"); test(1, B[2] == 0, "operator[] const fails?"); test(1, BB[2] == 0, "Array copy constructor fails? (array value not properly copied)"); A[2] = 1; test(2, BB[2] == 0, "Array copy constructor fails? (new table not allocated?)"); C = A; test(2, C[2] == 1 && C.size() == A.size(), "Array assignment operator fails?"); // test clear function Array D; SelfInitInt x; test(2, D[1].i == x.i, "Array declared without default value should not be initialized"); D[1].i = 10; D.clear(); test(2, D.size() == 0, "Array size() should return 0 after being clear()ed."); test(2, D[1].i == x.i, "Array clear() operation should allocate new table (this one is subtle)."); // try to test grow function Array E(1); int errors = 0; for (int i = 0; i < 10000; ++i) { E[i] = i; } for (int i = 0; i < 10000; ++i) { if (E[i] != i) ++errors; } test(3, errors == 0, "Array grow function failing?"); // end test_report(); }