You are here:   ArielOrtiz.com > 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

The lab activities can be developed individually or in pairs.

The lab report must be developed individually.

  1. Take a quick glance at the documentation for the Ruby Unit Testing Framework. 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 test_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: 18-Jan-2011
    # Authors:
    # 456654  Anthony Stark 
    # 1160611 Thursday Rubinstein
  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. For example:
    "front -> [1, 2, 3, 4] <- back".
  4. In the test_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 nil is returned by front 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 Thursday, January 20.

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.
© 1996-2011 by Ariel Ortiz (ariel.ortiz@itesm.mx)
Made with Django | Licensed under Creative Commons | Valid XHTML | Valid CSS