1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
list.Sort();
Test(list.ToString() == "StRiNg #1, sTrInG #10, StRiNg #11, sTrInG #12, StRiN"
"g #13, sTrInG #14, StRiNg #15, sTrInG #16, StRiNg #17, sTrInG #18, StRiN"
"g #19, sTrInG #2, sTrInG #20, StRiNg #21, sTrInG #22, StRiNg #23, sTrInG"
" #24, StRiNg #25, sTrInG #26, StRiNg #27, sTrInG #28, StRiNg #29, StRiNg"
" #3, sTrInG #30, StRiNg #31, sTrInG #4, StRiNg #5, sTrInG #6, StRiNg #7,"
" sTrInG #8, StRiNg #9",
"Sort() && ToString()");
cout << "Testing Overloaded <<:\n" << list << endl;
cout << "\n*****Member Functions with 1000 Items*****\n";
for (int i = 0; i < 969; i++)
list.AddFront(new string("A"));
Test(list.GetSize() == 1000, "AddFront(Adding 969 More Items) / GetSize()");
Test(list.GetCapacity() == 1000, "GetCapacity()");
cout << "\n*****Clearing All Items*****\n";
list.Clear();
Test(list.GetSize() == 0, "Clear() && GetSize()");
Test(list.GetCapacity() == 1000, "GetCapacity()");
Test(list.ToString() == "", "ToString()");
Test(list.Empty() == true, "Empty()");
try {
list.At(0);
} catch (const string &e) {
Test(e == "Invalid Location", "At(0) EXCEPTION HANDLING");
}
try {
list.GetFirst();
} catch (const string &e) {
Test(e == "Array Empty", "GetFirst() EXCEPTION HANDLING");
}
try {
list.GetLast();
} catch (const string &e) {
Test(e == "Array Empty", "GetLast() EXCEPTION HANDLING");
}
try {
list.DeleteFront();
} catch (const string &e) {
Test(e == "Array Empty", "DeleteFront() EXCEPTION HANDLING");
}
try {
list.DeleteBack();
} catch (const string &e) {
Test(e == "Array Empty", "DeleteBack() EXCEPTION HANDLING");
}
cout << "\n*****Member Functions with 1 Item*****\n";
list.AddFront(new string("Hello"));
Test(list.GetSize() == 1, "AddFront(\"Hello\") && GetSize()");
Test(list.GetCapacity() == 1000, "GetCapacity()");
Test(list.ToString() == "Hello", "ToString()");
Test(list.Empty() == false, "Empty()");
try {
list.At(1);
} catch (const string &e) {
Test(e == "Invalid Location", "At(1) EXCEPTION HANDLING");
}
Test(*list.At(0) == "Hello", "At(0)");
Test(*list.GetFirst() == "Hello", "GetFirst()");
Test(*list.GetLast() == "Hello", "GetLast()");
cout << "Testing Overloaded <<:\n" << list << endl;
// Tests
cout << "\n*****Overloaded Constructor*****\n";
DynamicStringArray list2(0);
Test(list2.GetSize() == 0, "DynamicStringArray(0) && GetSize()");
Test(list2.GetCapacity() == 10, "GetCapacity()");
Test(list2.ToString() == "", "ToString()");
Test(list2.Empty() == true, "Empty()");
try {
list2.At(0);
} catch (const string &e) {
Test(e == "Invalid Location", "At(0) EXCEPTION HANDLING");
}
try {
list2.GetFirst();
} catch (const string &e) {
Test(e == "Array Empty", "GetFirst() EXCEPTION HANDLING");
}
try {
list2.GetLast();
} catch (const string &e) {
Test(e == "Array Empty", "GetLast() EXCEPTION HANDLING");
}
try {
list2.DeleteFront();
} catch (const string &e) {
Test(e == "Array Empty", "DeleteFront() EXCEPTION HANDLING");
}
try {
list2.DeleteBack();
} catch (const string &e) {
Test(e == "Array Empty", "DeleteBack() EXCEPTION HANDLING");
}
DynamicStringArray list3(758);
Test(list3.GetSize() == 0, "DynamicStringArray(758) && GetSize()");
Test(list3.GetCapacity() == 758, "GetCapacity()");
Test(list3.ToString() == "", "ToString()");
Test(list3.Empty() == true, "Empty()");
try {
list3.At(0);
} catch (const string &e) {
Test(e == "Invalid Location", "At(0) EXCEPTION HANDLING");
}
try {
list3.GetFirst();
} catch (const string &e) {
Test(e == "Array Empty", "GetFirst() EXCEPTION HANDLING");
}
try {
list3.GetLast();
} catch (const string &e) {
Test(e == "Array Empty", "GetLast() EXCEPTION HANDLING");
}
try {
list3.DeleteFront();
} catch (const string &e) {
Test(e == "Array Empty", "DeleteFront() EXCEPTION HANDLING");
}
try {
list3.DeleteBack();
} catch (const string &e) {
Test(e == "Array Empty", "DeleteBack() EXCEPTION HANDLING");
}
// Testing Destructors
cout << "\n*****Testing Destructor*****" << endl
<< "If the next line is the \"END Testing Destructor\" then you passed!"
<< endl;
DynamicStringArray *dynamic_list = new DynamicStringArray();
delete dynamic_list;
dynamic_list = new DynamicStringArray();
for (int i = 0; i < 50; i++)
dynamic_list->AddFront(new string("testing"));
delete dynamic_list;
cout << "*****END Testing Destructor*****" << endl << endl;
cout << string(40, '-') << endl;
cout << "Passed: " << ut_passed << " / " << ut_total << endl;
OutputFailedTests();
cout << string(40, '-') << endl;
cout << "Unit Test Complete!\n";
cout << string(40, '-') << endl;
}
// For testing (DO NOT ALTER)
void Test(bool test, string more_info) {
static int test_number = 1;
ut_total++;
if (test) {
cout << "PASSSED TEST ";
ut_passed++;
} else {
cout << "FAILED TEST ";
ut_failed++;
failed_tests.push_back(ut_total);
}
cout << test_number << " " << more_info << "!" << endl;
test_number++;
}
void OutputFailedTests() {
if (failed_tests.size()) {
cout << "Failed test number(s): ";
for (unsigned int i = 0; i < failed_tests.size() - 1; i++)
cout << failed_tests.at(i) << ", ";
cout << failed_tests.at(failed_tests.size() - 1) << endl;
}
}
|