container_test::StackImpl_test Class Reference

Unit tests for StackImpl. More...

Collaboration diagram for container_test::StackImpl_test:

Collaboration graph
[legend]

List of all members.

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

OrderedListtestData


Detailed Description

Unit tests for StackImpl.

Constructor & Destructor Documentation

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    }

Here is the call graph for this function:

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    }


Member Function Documentation

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    }

Here is the call graph for this function:

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    }

Here is the call graph for this function:

virtual void container_test::StackImpl_test::SetUp (  )  [inline, protected, virtual]

00087                         {
00088       // Code here will be called immediately after the constructor (right
00089       // before each test).
00090    }

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    }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void container_test::StackImpl_test::TearDown (  )  [inline, protected, virtual]

00092                            {
00093       // Code here will be called immediately after each test (right
00094       // before the destructor).
00095    }

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    }

Here is the call graph for this function:

Here is the caller graph for this function:

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    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation


The documentation for this class was generated from the following file:

Generated on Tue Jun 16 23:13:03 2009 by  doxygen 1.5.9