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.
IMPORTANT NOTE: 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 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
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" .
|
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).
To hand in your individual lab work, follow these instructions.
lab1_report_A0MMMMMMM.txt
, where A0MMMMMMM
is your student ID. From your AsciiDoc source, generate the corresponding HTML5 file. That file should be called lab1_report_A0MMMMMMM.html
. Place these two files in the deque
directory.
deque
directory. Call this file deque.tgz
. From a terminal, you can use the following command to create this file (make sure to run it at the same level where the deque
folder resides):
tar czf deque.tgz deque
Due date is Tuesday, January 29.
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. |