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.
The lab activities can be developed individually or in pairs.
The lab report must be developed individually.
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
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" .
|
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).
To hand in your individual lab work, follow these instructions.
lab1_report_A0MMMMMMM.tex
, where A0MMMMMMM
is your student ID. From your LaTeX source, generate the
corresponding PDF file. That file should be called
lab1_report_A0MMMMMMM.pdf
. Place these two files in the
deque
directory.
deque
directory. Call this file deque.zip
.
Due date is Thursday, January 20.
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. |