Protected Member Functions | |
QueueImpl_test () | |
virtual | ~QueueImpl_test () |
virtual void | SetUp () |
virtual void | TearDown () |
void | verifyQueueCoherence (Queue *q, const int count=0) |
void | startingEmpty (Queue *q) |
void | enqueueDequeueTest (Queue *q) |
void | firstTenPresidents (Queue *q) |
Copy testData and add copy to q. | |
void | purgeContentsTest (Queue *q) |
void | verifyEquivalence (Queue *orig, Queue *copy, bool deepCopy) |
void | shallowVersusDeepTest (Queue *q) |
Protected Attributes | |
OrderedList * | testData |
container_test::QueueImpl_test::QueueImpl_test | ( | ) | [inline, protected] |
00062 { 00063 // You can do set-up work for each test here. 00064 00065 testData = new OrderedArrayList(10, 5); 00066 testData->append(new Person("George", "Washington")); 00067 testData->append(new Person("John", "Adams")); 00068 testData->append(new Person("Thomas", "Jefferson")); 00069 testData->append(new Person("James", "Madison")); 00070 testData->append(new Person("James", "Monroe")); 00071 testData->append(new Person("John Quincy", "Adams")); 00072 testData->append(new Person("Andrew", "Jackson")); 00073 testData->append(new Person("Marin", "Van Buren")); 00074 testData->append(new Person("William Henry", "Harrison")); 00075 testData->append(new Person("John", "Tyler")); 00076 }
virtual container_test::QueueImpl_test::~QueueImpl_test | ( | ) | [inline, protected, virtual] |
00078 { 00079 // You can do clean-up work that doesn't throw exceptions here. 00080 00081 delete testData; 00082 }
void container_test::QueueImpl_test::enqueueDequeueTest | ( | Queue * | q | ) | [inline, protected] |
00143 { 00144 startingEmpty(q); 00145 00146 for (int i = 0; i < testData->getCount(); i++) { 00147 cout << " adding " << testData->entityAt(i) << endl; 00148 q->enqueue(testData->entityAt(i)); 00149 cout << " " << q << endl; 00150 verifyQueueCoherence(q, i + 1); 00151 } 00152 00153 cout << "Dequeueing items one by one:" << endl; 00154 for (int i = 0; i < testData->getCount(); i++) { 00155 Entity* e = q->dequeue(); 00156 EXPECT_EQ(testData->entityAt(i), e); 00157 cout << " [" << i << "]expected " << testData->entityAt(i) << endl; 00158 cout << " actual " << e << endl; 00159 verifyQueueCoherence(q, testData->getCount() - i - 1); 00160 } 00161 00162 cout << "Ending with an empty queue:" << endl; 00163 cout << " " << q << endl; 00164 00165 delete q; 00166 }
void container_test::QueueImpl_test::firstTenPresidents | ( | Queue * | q | ) | [inline, protected] |
Copy testData and add copy to q.
Helper method.
00173 { 00174 for (int i = 0; i < testData->getCount(); i++) { 00175 00176 Entity* e = testData->entityAt(i); 00177 Person* p = dynamic_cast<Person*>(e); 00178 00179 // use copy constructor 00180 Person* pCopy = new Person(*p); 00181 q->enqueue(pCopy); 00182 } 00183 }
void container_test::QueueImpl_test::purgeContentsTest | ( | Queue * | q | ) | [inline, protected] |
00185 { 00186 startingEmpty(q); 00187 00188 cout << "Purging an empty queue:" << endl; 00189 int n = q->purgeContents(); 00190 cout << " deleted " << n << " items" << endl; 00191 EXPECT_EQ(0, n); 00192 verifyQueueCoherence(q, 0); 00193 00194 cout << "Populating queue with first " << testData->getCount() << 00195 " presidents:" << endl; 00196 firstTenPresidents(q); 00197 cout << " " << q << endl; 00198 verifyQueueCoherence(q, testData->getCount()); 00199 00200 cout << "Purging:" << endl; 00201 n = q->purgeContents(); 00202 cout << " deleted " << n << " items" << endl; 00203 cout << " " << q << endl; 00204 EXPECT_EQ(testData->getCount(), n); 00205 verifyQueueCoherence(q, 0); 00206 00207 delete q; 00208 }
virtual void container_test::QueueImpl_test::SetUp | ( | ) | [inline, protected, virtual] |
void container_test::QueueImpl_test::shallowVersusDeepTest | ( | Queue * | q | ) | [inline, protected] |
00252 { 00253 firstTenPresidents(q); 00254 cout << "Starting with " << testData->getCount() << " People:" << endl; 00255 cout << " " << q << endl; 00256 verifyQueueCoherence(q, testData->getCount()); 00257 cout << "Creating shallow copy:" << endl; 00258 Queue* qCopy = dynamic_cast<Queue*>(q->clone(false)); 00259 cout << " " << qCopy << endl; 00260 verifyQueueCoherence(qCopy, testData->getCount()); 00261 verifyEquivalence(q, qCopy, false); 00262 00263 while (!qCopy->isEmpty()) { 00264 qCopy->dequeue(); 00265 } 00266 verifyQueueCoherence(qCopy, 0); 00267 delete qCopy; 00268 verifyQueueCoherence(q, testData->getCount()); 00269 00270 cout << "Creating deep copy:" << endl; 00271 qCopy = dynamic_cast<Queue*>(q->clone(true)); 00272 cout << " " << qCopy << endl; 00273 verifyQueueCoherence(qCopy, testData->getCount()); 00274 verifyEquivalence(q, qCopy, true); 00275 00276 delete q; 00277 verifyQueueCoherence(qCopy, testData->getCount()); 00278 delete qCopy; 00279 }
void container_test::QueueImpl_test::startingEmpty | ( | Queue * | q | ) | [inline, protected] |
00136 { 00137 cout << "Starting with an empty queue:" << endl; 00138 cout << " " << q << endl; 00139 EXPECT_EQ(0, q->getCount()); 00140 verifyQueueCoherence(q, 0); 00141 }
virtual void container_test::QueueImpl_test::TearDown | ( | ) | [inline, protected, virtual] |
void container_test::QueueImpl_test::verifyEquivalence | ( | Queue * | orig, | |
Queue * | copy, | |||
bool | deepCopy | |||
) | [inline, protected] |
00210 { 00211 cout << " orig->typeInfo():" << endl; 00212 cout << " original " << orig->typeInfo() << endl; 00213 cout << " copy " << copy->typeInfo() << endl; 00214 EXPECT_EQ(orig->typeInfo(), copy->typeInfo()); 00215 cout << " getCount():" << endl; 00216 cout << " original " << orig->getCount() << endl; 00217 cout << " copy " << copy->getCount() << endl; 00218 EXPECT_EQ(orig->getCount(), copy->getCount()); 00219 cout << " isEmpty():" << endl; 00220 cout << " original " << orig->isEmpty() << endl; 00221 cout << " copy " << copy->isEmpty() << endl; 00222 EXPECT_EQ(orig->isEmpty(), copy->isEmpty()); 00223 if (deepCopy) { 00224 cout << " Deep copy should create new, independent People objects:" << endl; 00225 } else { 00226 cout << " Shallow copy should share the same People objects:" << endl; 00227 } 00228 for (int i = 0; i < orig->getCount(); i++) { 00229 Person* op = dynamic_cast<Person*>(orig->dequeue()); 00230 Person* cp = dynamic_cast<Person*>(copy->dequeue()); 00231 orig->enqueue(op); 00232 copy->enqueue(cp); 00233 cout << " [" << i << "]" << endl; 00234 cout << " original pointer value " << ((void*)op) << endl; 00235 cout << " copy pointer value " << ((void*)cp) << endl; 00236 op->setFirstName(op->getFirstName().append(" Albert")); 00237 if (deepCopy) { 00238 EXPECT_NE(op, cp); 00239 cout << " Change to one won't affect the other:" << endl; 00240 EXPECT_NE(op->getFirstName(), cp->getFirstName()); 00241 } else { 00242 EXPECT_EQ(op, cp); 00243 cout << " Change to one will affect the other:" << endl; 00244 EXPECT_EQ(op->getFirstName(), cp->getFirstName()); 00245 } 00246 cout << " original " << op << endl; 00247 cout << " copy " << cp << endl; 00248 } 00249 00250 }
void container_test::QueueImpl_test::verifyQueueCoherence | ( | Queue * | q, | |
const int | count = 0 | |||
) | [inline, protected] |
00099 { 00100 EXPECT_TRUE(count >= 0); 00101 EXPECT_TRUE(q->getCount() >= 0); 00102 EXPECT_EQ(count, q->getCount()); 00103 if (count == 0) { 00104 EXPECT_TRUE(q->isEmpty()); 00105 EXPECT_TRUE(q->dequeue() == NULL); 00106 } else { 00107 EXPECT_FALSE(q->isEmpty()); 00108 } 00109 00110 OrderedList* list = new OrderedArrayList(); 00111 int n = count; 00112 while (!q->isEmpty()) { 00113 Entity* e = q->dequeue(); 00114 EXPECT_TRUE(e != NULL); 00115 list->append(e); 00116 n--; 00117 EXPECT_EQ(q->getCount(), n); 00118 } 00119 00120 EXPECT_TRUE(q->getCount() == 0); 00121 EXPECT_TRUE(q->isEmpty()); 00122 EXPECT_TRUE(q->dequeue() == NULL); 00123 00124 for (int i = 0; i < list->getCount(); i++) { 00125 q->enqueue(list->entityAt(i)); 00126 } 00127 00128 EXPECT_EQ(q->getCount(), count); 00129 00130 while (list->toFirst()) { 00131 list->extractCurrentEntity(); 00132 } 00133 delete list; 00134 }
OrderedList* container_test::QueueImpl_test::testData [protected] |