Protected Member Functions | |
StackImpl_test () | |
virtual | ~StackImpl_test () |
virtual void | SetUp () |
virtual void | TearDown () |
void | verifyStackCoherence (Stack *s, const int count=0) |
void | startingEmpty (Stack *s) |
void | pushPopTest (Stack *s) |
void | tenPhysicists (Stack *s) |
Copy testData and add copy to s. | |
void | purgeContentsTest (Stack *s) |
Protected Attributes | |
OrderedList * | testData |
container_test::StackImpl_test::StackImpl_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("Marie", "Curie")); 00067 testData->append(new Person("Max", "Planck")); 00068 testData->append(new Person("Albert", "Einstein")); 00069 testData->append(new Person("Niels", "Bohr")); 00070 testData->append(new Person("Enrico", "Fermi")); 00071 testData->append(new Person("Ernest", "Lawrence")); 00072 testData->append(new Person("Richard", "Feynman")); 00073 testData->append(new Person("Arno Allan", "Penzias")); 00074 testData->append(new Person("Gerd", "Binnig")); 00075 testData->append(new Person("Steven", "Chu")); 00076 }
virtual container_test::StackImpl_test::~StackImpl_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::StackImpl_test::purgeContentsTest | ( | Stack * | s | ) | [inline, protected] |
00184 { 00185 startingEmpty(s); 00186 00187 cout << "Purging an empty stack:" << endl; 00188 int n = s->purgeContents(); 00189 cout << " deleted " << n << " items" << endl; 00190 EXPECT_EQ(0, n); 00191 verifyStackCoherence(s, 0); 00192 00193 cout << "Populating stack with " << testData->getCount() << 00194 " physicists:" << endl; 00195 tenPhysicists(s); 00196 cout << " " << s << endl; 00197 verifyStackCoherence(s, testData->getCount()); 00198 00199 cout << "Purging:" << endl; 00200 n = s->purgeContents(); 00201 cout << " deleted " << n << " items" << endl; 00202 cout << " " << s << endl; 00203 EXPECT_EQ(testData->getCount(), n); 00204 verifyStackCoherence(s, 0); 00205 00206 delete s; 00207 }
void container_test::StackImpl_test::pushPopTest | ( | Stack * | s | ) | [inline, protected] |
00140 { 00141 startingEmpty(s); 00142 00143 for (int i = 0; i < testData->getCount(); i++) { 00144 cout << " adding " << testData->entityAt(i) << endl; 00145 s->push(testData->entityAt(i)); 00146 cout << " " << s << endl; 00147 verifyStackCoherence(s, i + 1); 00148 } 00149 00150 cout << "Poping items one by one:" << endl; 00151 for (int i = 0; i < testData->getCount(); i++) { 00152 Entity* e = s->pop(); 00153 int expectedIndex = testData->getCount() - i - 1; 00154 EXPECT_EQ(testData->entityAt(expectedIndex), e); 00155 cout << " [" << i << "]expected " << 00156 testData->entityAt(expectedIndex) << endl; 00157 cout << " actual " << e << endl; 00158 verifyStackCoherence(s, expectedIndex); 00159 } 00160 00161 cout << "Ending with an empty stack:" << endl; 00162 cout << " " << s << endl; 00163 00164 delete s; 00165 }
virtual void container_test::StackImpl_test::SetUp | ( | ) | [inline, protected, virtual] |
void container_test::StackImpl_test::startingEmpty | ( | Stack * | s | ) | [inline, protected] |
00133 { 00134 cout << "Starting with an empty stack:" << endl; 00135 cout << " " << s << endl; 00136 EXPECT_EQ(0, s->getCount()); 00137 verifyStackCoherence(s, 0); 00138 }
virtual void container_test::StackImpl_test::TearDown | ( | ) | [inline, protected, virtual] |
void container_test::StackImpl_test::tenPhysicists | ( | Stack * | s | ) | [inline, protected] |
Copy testData and add copy to s.
Helper method.
00172 { 00173 for (int i = 0; i < testData->getCount(); i++) { 00174 00175 Entity* e = testData->entityAt(i); 00176 Person* p = dynamic_cast<Person*>(e); 00177 00178 // use copy constructor 00179 Person* pCopy = new Person(*p); 00180 s->push(pCopy); 00181 } 00182 }
void container_test::StackImpl_test::verifyStackCoherence | ( | Stack * | s, | |
const int | count = 0 | |||
) | [inline, protected] |
00099 { 00100 EXPECT_TRUE(count >= 0); 00101 EXPECT_TRUE(s->getCount() >= 0); 00102 EXPECT_EQ(s->getCount(), count); 00103 if (count == 0) { 00104 EXPECT_TRUE(s->isEmpty()); 00105 EXPECT_TRUE(s->pop() == NULL); 00106 } else { 00107 EXPECT_FALSE(s->isEmpty()); 00108 } 00109 00110 OrderedList* list = new OrderedArrayList(); 00111 int n = count; 00112 while (!s->isEmpty()) { 00113 Entity* e = s->pop(); 00114 EXPECT_TRUE(e != NULL); 00115 list->append(e); 00116 n--; 00117 EXPECT_EQ(s->getCount(), n); 00118 } 00119 00120 EXPECT_TRUE(s->getCount() == 0); 00121 EXPECT_TRUE(s->isEmpty()); 00122 EXPECT_TRUE(s->pop() == NULL); 00123 00124 while (list->toLast()) { 00125 s->push(list->extractCurrentEntity()); 00126 } 00127 00128 EXPECT_EQ(s->getCount(), count); 00129 00130 delete list; 00131 }
OrderedList* container_test::StackImpl_test::testData [protected] |