You are here:   ArielOrtiz.info > Software Design and Architecture > Lab 1: Unit Testing

Lab 1: Unit Testing

Objectives

During this lab session:

This activity helps students develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.

Activity Description

IMPORTANT NOTE: The lab activities can be developed individually or in pairs. The lab report must be developed individually.

  1. Take a quick glance at the chapter on Unit testing from the Ruby Programming Wikibook. This information will come in handy in a later step.
  2. Create a folder called deque. Inside this folder, create two files called deque.rb and tc_deque.rb.

    Both Ruby source files must start with a comment containing the lab’s title, date, and the authors’ personal information. For example:

    # Lab 1: Unit Testing
    # Date: 23-Jan-2013
    # Authors:
    # 456654  Thursday Rubinstein  
    # 1160611 Anthony Stark
    
  3. In the deque.rb source file, write a class called Deque (pronounced deck) that implements a double-ended queue. A deque is a data structure that implements a queue for which elements can only be added to or removed from the front or back.

    The following table describes the operations that this class must provide:

    Instance Method Description
    initialize(*elements) Initializes a new deque instance with all the arguments sent to this method.
    push_back(obj) Inserts obj at the back of this deque. Returns the deque itself, so that several operations can be chained together.
    push_front(obj) Inserts obj at the front of this deque. Returns the deque itself, so that several operations can be chained together.
    pop_back Removes the element from the back of this deque and returns it, or nil if the deque is empty.
    pop_front Removes the element from the front of this deque and returns it, or nil if the deque is empty.
    back Returns the element from the back of this deque without removing it, or nil if the deque is empty.
    front Returns the element from the front of this deque without removing it, or nil if the deque is empty.
    empty? Returns true if this deque contains no elements, otherwise returns false.
    length Returns the number of elements in this deque.
    size Alias for length.
    inspect Returns a string containing a human-readable representation of this deque. Something like this: "front -> [1, 2, 3, 4] <- back".
  4. In the tc_deque.rb file, write a test case class that verifies that every method in the previous step works as requested. Make sure to cover all cases in your tests (for example, that front returns nil when a deque is empty, in addition to its regular behavior).

Deliverables

To hand in your individual lab work, follow these instructions.

Due date is Tuesday, January 29.

Evaluation

This activity will be evaluated using the following criteria:

50% Implementation of functional requirements.
50% Lab report.
DA The program and/or report was plagiarized.