C M S C     2 1 4
C o m p u t e r   S c i e n c e   I I
F a l l   2 0 0 2


Unit Testing a Queue Class
An Extreme Programming Idea

To show the "power" of unit testing. You will be provided a header file for MovieALQueue, which is a queue class using a templatized ArrayList of Movie objects (AL means "ArrayList"). You will change the implementation, but leave the interface alone (except to add overloaded operators, for == and !=).

You should be able to recycle the same tests you used in Project 1 (add 2 more tests, to check for the other operators), and be done pretty quickly (unless, of course, you skipped that part).

Since you are doing black box testing (i.e., testing the public methods, without real knowledge of the data members), the tests should work the same.

Writing Test Code for MovieALQueue Class

Do the following:

The specifications for MovieALQueue are given below.

MovieALQueue Specifications

MovieALQueue

A MovieQueue is an ArrayList of Movie objects. This is NOT a sorted. In particular, enqueue() always adds to the end of the list (with the highest index), and dequeue() always removes from the front of the list (at index 0).

The size of the array list should always be the same as the number of elements in the list. DO NOT ADD public methods to push or pop from the front. You will need to shift, and resize.

Instance Variables

Declaration Description
ArrayList<Movie> list ; Stores list of Movie objects

Public Methods

MovieALQueue() ;
Default constructor. Doesn't do anything.
void enqueue( const Movie & movieIn ) ;
Pushes a movie at the end of the array list. This causes the size to increase by 1.
bool dequeue( Movie & movieOut ) ;
If there is a movie in the queue, then it removes the movie from the front of the queue. You will need to shift remaining movies to the left, and resize one size smaller (there is a short cut though, see public methods of ArrayList). Return true if there is at least one movie to be dequeued. Return false, if the size of the array list is 0.
void clear() ;
Resize the array list to 0.
bool isEmpty() const ;
Returns true if the queue is empty. Returns false, otherwise.
int size() const ;
Returns number of elements in the queue.

You should determine whether this class needs a copy constructor, assignment operator and destructor written. If so, add the methods above.

Then, implement the following private helper methods, and use them to implement the copy constructor, assignment operator and destructor.

Private Methods

void init() ;
Does what default constructor does (sets pointers to NULL, and size to 0). Should be called by the copy constructor before calling copy().
void copy( const MovieQueue & other ) ;
Copies other.
void freeMem() ;
Deallocate memory.

MovieALQueueUnit

You will be provided a partial MovieALQueueUnit header file. You should implement the code, and test.


See the class syllabus for policies concerning email
Last Modified: Sat Sep 14 16:07:25 EDT 2002
left up down right home

Web Accessibility