#include <sortedlist_test.h>
Protected Member Functions | |
SortedList_test () | |
virtual | ~SortedList_test () |
void | insertSorted (const Object::Info *type) |
void | insertingAndRemoving (const Object::Info *type) |
Protected Attributes | |
OrderedLinkedList | unsortedGroup |
OrderedLinkedList | sortedGroup |
Person * | joeSmith |
Person * | janeSmith |
Person * | fredHarris |
Person * | joseGonzales |
Person * | fernandaMijares |
OrderedLinkedList | otherUnsortedGroup |
OrderedLinkedList | otherSortedGroup |
Person * | otherJoeSmith |
Person * | otherJaneSmith |
Person * | otherFredHarris |
Person * | otherJoseGonzales |
Person * | otherFernandaMijares |
There are no actual unit tests in SortedList_test that the googletest framework will recognize and execute automatically. The googletest framework doesn't provide an elegant solution for testing the compliance of derived classes. This class is sub-classed by SortedLinkedList_test and SortedArrayList_test in order to re-use common unit test code.
container_test::SortedList_test::SortedList_test | ( | ) | [protected] |
00047 { 00048 string joe = "Joe"; 00049 string smith = "Smith"; 00050 string jane = "Jane"; 00051 string fred = "Fred"; 00052 string harris = "Harris"; 00053 string jose = "Jose"; 00054 string gonzales = "Gonzales"; 00055 string fernanda = "Fernanda"; 00056 string mijares = "Mijares"; 00057 joeSmith = new Person(joe, smith); 00058 janeSmith = new Person(jane, smith); 00059 fredHarris = new Person(fred, harris); 00060 joseGonzales = new Person(jose, gonzales); 00061 fernandaMijares = new Person(fernanda, mijares); 00062 00063 unsortedGroup.add(joeSmith); 00064 unsortedGroup.add(janeSmith); 00065 unsortedGroup.add(fredHarris); 00066 unsortedGroup.add(joseGonzales); 00067 unsortedGroup.add(fernandaMijares); 00068 00069 sortedGroup.add(joseGonzales); 00070 sortedGroup.add(fredHarris); 00071 sortedGroup.add(fernandaMijares); 00072 sortedGroup.add(janeSmith); 00073 sortedGroup.add(joeSmith); 00074 00075 otherJoeSmith = new Person(joe, smith); 00076 otherJaneSmith = new Person(jane, smith); 00077 otherFredHarris = new Person(fred, harris); 00078 otherJoseGonzales = new Person(jose, gonzales); 00079 otherFernandaMijares = new Person(fernanda, mijares); 00080 00081 otherUnsortedGroup.add(otherJoeSmith); 00082 otherUnsortedGroup.add(otherJaneSmith); 00083 otherUnsortedGroup.add(otherFredHarris); 00084 otherUnsortedGroup.add(otherJoseGonzales); 00085 otherUnsortedGroup.add(otherFernandaMijares); 00086 00087 otherSortedGroup.add(otherJoseGonzales); 00088 otherSortedGroup.add(otherFredHarris); 00089 otherSortedGroup.add(otherFernandaMijares); 00090 otherSortedGroup.add(otherJaneSmith); 00091 otherSortedGroup.add(otherJoeSmith); 00092 }
container_test::SortedList_test::~SortedList_test | ( | ) | [protected, virtual] |
00094 { 00095 // You can do clean-up work that doesn't throw exceptions here. 00096 while (sortedGroup.toFirst()) { 00097 sortedGroup.extractCurrentEntity(); 00098 } 00099 while (otherSortedGroup.toFirst()) { 00100 otherSortedGroup.extractCurrentEntity(); 00101 } 00102 }
void container_test::SortedList_test::insertingAndRemoving | ( | const Object::Info * | type | ) | [protected] |
00185 { 00186 SortedList* a = sortedListFactory(type); 00187 const int LIST_SIZE = 5; 00188 Entity ** data; 00189 generateDataAndPopulateList(data, a, LIST_SIZE, true); 00190 00191 EXPECT_TRUE(a->toFirst()); 00192 cout << "Iterating from first to last." << endl; 00193 for (int i = 0; !a->isTail(); i++ + a->toNext()) { 00194 cout << " node[" << i << "] contains: " << *a->currentEntity() << endl; 00195 EXPECT_EQ(data[i], a->currentEntity()); 00196 EXPECT_TRUE(data[i] == a->currentEntity()); 00197 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE); 00198 } 00199 verifyNonEmptyStateCoherence_tail(*a, LIST_SIZE); 00200 00201 cout << "Iterating from last to first." << endl; 00202 for (int i = (LIST_SIZE - 1); a->toPrev(); i--) { 00203 cout << " node[" << i << "] contains: " << *a->currentEntity() << endl; 00204 EXPECT_EQ(data[i], a->currentEntity()); 00205 EXPECT_TRUE(data[i]->compareKeyTo(*a->currentEntity()) == 0); 00206 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE); 00207 } 00208 EXPECT_TRUE(a->isFirst()); 00209 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE); 00210 00211 cout << "Extracting from first to last." << endl; 00212 int index = 0; 00213 do { 00214 Entity *e = a->extractCurrentEntity(); 00215 cout << " extracted " << *e << endl; 00216 cout << " " << a << endl; 00217 EXPECT_EQ(data[index], e); 00218 EXPECT_TRUE(data[index]->compareKeyTo(*e) == 0); 00219 if (index < (LIST_SIZE - 1)) { 00220 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE - index - 1); 00221 } else { 00222 verifyEmptyStateCoherence(*a); 00223 } 00224 index++; 00225 } while (!a->isTail()); 00226 00227 cout << "Repopulating same list with extracted Entities" << endl; 00228 cout << " " << a << endl; 00229 for (int i = 0; i < LIST_SIZE; i++) { 00230 a->insertSorted(data[i]); 00231 cout << " After insertSorted() " << *data[i] << endl; 00232 cout << " " << a << endl; 00233 verifyNonEmptyStateCoherence_tail(*a, i + 1); 00234 } 00235 00236 cout << "Deleting from first to last." << endl; 00237 index = 0; 00238 a->toFirst(); 00239 do { 00240 EXPECT_EQ(data[index], a->currentEntity()); 00241 EXPECT_TRUE(a->deleteCurrent()); 00242 cout << " deleteCurrent()" << endl; 00243 cout << " " << a << endl; 00244 if (index < (LIST_SIZE - 1)) { 00245 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE - index - 1); 00246 } else { 00247 verifyEmptyStateCoherence(*a); 00248 } 00249 index++; 00250 } while (!a->isTail()); 00251 00252 delete a; 00253 delete data; 00254 }
void container_test::SortedList_test::insertSorted | ( | const Object::Info * | type | ) | [protected] |
00108 { 00109 SortedList *a = sortedListFactory(type); 00110 cout << "Starting with an empty " << type->typeName << ":" << endl; 00111 cout << " " << a << endl; 00112 int i = 0; 00113 for (unsortedGroup.toFirst(); !unsortedGroup.isTail(); unsortedGroup.toNext()) { 00114 cout << " Adding " << unsortedGroup.currentEntity()->getKeyAsString(); 00115 EXPECT_TRUE(a->insertSorted(unsortedGroup.currentEntity())); 00116 i++; 00117 cout << "; result: " << a << endl; 00118 verifyNonEmptyStateCoherence_tail(a, i); 00119 00120 // Verify that all added Person objects can be located and that ones 00121 // yet to be added cannot be located. 00122 for (int j = 0; j < unsortedGroup.getCount(); j++) { 00123 Entity* e1 = unsortedGroup.entityAt(j); 00124 Entity* oe1 = otherUnsortedGroup.entityAt(j); 00125 // The content of otherUnsortedGroup should match unsortedGroup but 00126 // should contain unique instances. 00127 EXPECT_NE(e1, oe1); 00128 EXPECT_EQ(e1->getKeyAsString(), oe1->getKeyAsString()); 00129 EXPECT_TRUE(e1->compareKeyTo(*oe1) == 0); 00130 00131 int index; 00132 Entity* e2; 00133 if ((i % 2) == 0) { 00134 // locate by the same Entity instance 00135 a->locateEntity(*e1, index, e2); 00136 } else { 00137 // locate by a different Entity instance with matching key 00138 a->locateEntity(*oe1, index, e2); 00139 } 00140 if (j < i) { 00141 EXPECT_NE(List::NO_MATCHING_ENTITY_INDEX_FLAG, index); 00142 EXPECT_EQ(e1, e2); 00143 EXPECT_NE(e1, oe1); 00144 EXPECT_TRUE(e1->compareKeyTo(*e2) == 0); 00145 EXPECT_TRUE(oe1->compareKeyTo(*e2) == 0); 00146 EXPECT_EQ(e1, a->entityAt(index)); 00147 00148 // verify that duplicates are rejected 00149 cout << " Attempting to add duplicate e1 " << e1->getKeyAsString() << endl; 00150 cout << " a->insertSorted(e1) returns: " << (a->insertSorted(e1) ? "true" : "false") << endl; 00151 cout << " a->getCount() returns: " << a->getCount() << endl; 00152 EXPECT_FALSE(a->insertSorted(e1)); 00153 verifyNonEmptyStateCoherence_tail(a, i); 00154 EXPECT_FALSE(a->insertSorted(oe1)); 00155 verifyNonEmptyStateCoherence_tail(a, i); 00156 } else { 00157 EXPECT_EQ(List::NO_MATCHING_ENTITY_INDEX_FLAG, index); 00158 EXPECT_TRUE(e2 == NULL); 00159 } 00160 } 00161 } 00162 00163 cout << "Checking for expected sorted order." << endl; 00164 i = 0; 00165 for (a->toFirst(); !a->isTail(); a->toNext()) { 00166 Entity* e1 = sortedGroup.entityAt(i); 00167 Entity* oe1 = otherSortedGroup.entityAt(i); 00168 Entity* e2 = a->currentEntity(); 00169 cout << " [" << i << "]expected: " << e1 << endl; 00170 cout << " actual: " << e2 << endl; 00171 EXPECT_EQ(e1, e2); 00172 EXPECT_NE(e1, oe1); 00173 EXPECT_TRUE(e1->compareKeyTo(*e2) == 0); 00174 EXPECT_TRUE(oe1->compareKeyTo(*e2) == 0); 00175 i++; 00176 } 00177 00178 while (a->toFirst()) { 00179 a->extractCurrentEntity(); 00180 } 00181 00182 delete a; 00183 }
Person* container_test::SortedList_test::fernandaMijares [protected] |
Person* container_test::SortedList_test::fredHarris [protected] |
Person* container_test::SortedList_test::janeSmith [protected] |
Person* container_test::SortedList_test::joeSmith [protected] |
Person* container_test::SortedList_test::joseGonzales [protected] |
Person* container_test::SortedList_test::otherFredHarris [protected] |
Person* container_test::SortedList_test::otherJaneSmith [protected] |
Person* container_test::SortedList_test::otherJoeSmith [protected] |
Person* container_test::SortedList_test::otherJoseGonzales [protected] |