#include "Vector.h" #include #include using std::cout; using std::endl; void test_constructor(); void test_access(); void test_insert(); void test_delete(); void test_find(); int main(){ test_constructor(); test_access(); test_insert(); test_delete(); test_find(); system("pause"); return 0; } void test_constructor() { cout << "run test_constructor..."; Vector V; assert(V.empty()); assert(V.getCapacity() == DEFAULT_CAPACITY); Vector V1(10); assert(V1.empty()); assert(V1.getCapacity() == 10); int A[10] = { 2,3,4,6,1,0,9,8,7,5 }; Vector V2(A, 10); assert(V2.getSize() == 10); assert(V2.getCapacity() == 20); assert(!V2.empty()); Vector V3(A, 3, 7); assert(V3.getSize() == 4); assert(V3.getCapacity() == 8); Vector V4(V3); assert(V4.getSize() == 4); assert(V4.getCapacity() == 8); Vector V5(V4, 2, 4); assert(V5.getSize() == 2); assert(V5.getCapacity() == 4); cout << "test passed." << endl; } void test_access(){ cout << "run test_access..."; int A[] = { 2,3,4,6,1,0,9,8,7,5 }; Vector v(A, 10); //test Vector::get method for (int ix = 0; ix != 10; ++ix) assert(v.get(ix) == A[ix]); //test Vector::replace method int val = 12; v.replace(0, 12); v.replace(5, 12); assert(v[0] == 12); assert(v[5] == 12); //test [] v[1] = val; v[2] = val; assert(v[1] == val); assert(v[2] == val); cout << "test passed." << endl; } void test_insert(){ cout << "run test_insert..."; int A[] = { 2,3,4,6,1,0,9,8,7,5 }; Vector v(A, 10); v.push_back(12); v.insert(2, 15); assert(v.getSize() == 12); assert(v.getCapacity() == 20); assert(v[11] == 12); assert(v[2] == 15); cout << "test passed." << endl; } void test_delete(){ cout << "run test_delete..."; int A[] = { 2,3,4,6,1,0,9,8,7,5 }; Vector v(A, 10); assert(v.pop_back() == 5); assert(v.pop(5) == 0); assert(v.pop(4, 6) == 9); assert(v.getSize() == 6); assert(v.remove(8) == 4); assert(v.remove(12) == -1); cout << "test passed." << endl; } void test_find(){ cout << "run test_find..."; int A[] = { 2,3,4,6,1,0,9,8,7,5 }; Vector v(A, 10); assert(v.find(4) == 2); assert(v.find(5) == 9); assert(v.find(11) == -1); assert(v.find(4, 2, 8) == 2); assert(v.find(4, 5, 8) == 4); cout << "test passed." << endl; }