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.
This lab can be developed individually or in pairs.
Create a folder called deque_mixin
. Inside this
folder, create two files called deque_mixin.rb
and
test_deque_mixin.rb
.
Both Ruby source files must start with a comment containing the lab's title, date, and the authors' personal information. For example:
# Lab 2: Mixins # Date: 27-Aug-2009 # Authors: # 456654 Anthony Stark # 1160611 Thursday Rubinstein
The following is one possible implementation of the
Deque
class you wrote for last week's lab (copy
this code into the deque_mixin.rb
file):
class Deque def initialize *elements @info = elements end def push_back x @info.push x self end def push_front x @info.unshift x self end def pop_back @info.pop end def pop_front @info.shift end def back @info.last end def front @info.first end def empty? @info.empty? end def length @info.length end alias size length def inspect "front -> #{ @info.inspect } <- back" end end
You must mixin the Enumerable
module into the
Deque
class. Make sure to provide a correct
implementation of the each
method.
test_deque_mixin.rb
file, write a test case
class that verifies that the following Enumerable
methods works as described in the documentation:
all?
,
any?
,
collect
(alias map
),
detect
(alias find
),
each_with_index
,
find_all
(alias select
),
grep
,
include?
(alias member?
),
inject
,
max
,
min
,
reject
,
sort
,
sort_by
,
to_a
(alias entries
), and
zip
.
To hand in your lab work, follow these instructions:
deque_mixin
directory. Call this file
deque_mixin.zip
.
This activity will be evaluated using the following criteria:
100 | The code works as requested. |
---|---|
60-90 | The code works, but has some flaws. |
20-50 | The code doesn't work, but it seams that some amount of time was spent on it. |
DA | The program was plagiarized. |