The three rules of Ruby Q.:
Please do not post any solutions or spoiler discussion for this quiz
48 hours have passed from the time on this message.
Support Ruby Q. by submitting ideas as often as you can:
Suggestion: A [QUIZ] in the subject of emails about the problem helps
on Ruby T. follow the discussion.
by Robert F.
In this week’s Ruby Q. you will not only have fun and (hopefully)
something; you will also contribute to a research project evaluating
testing techniques. So please read on and then take the quiz!
The goal of this quiz is to write a good and extensive test suite for a
DiGraph (directed graph) class. The new (hotshot, and annoying ;))
manager at your work has challenged all the developers. He is planning
cutbacks since he claims that automated testing tools can do as good or
job! The focus of the testing is on the following two methods of the
# Return the length of the longest simple path (an arc/edge can only # occur once in the path) that includes <node>. DiGraph#max_length_of_simple_path_including_node(node) # Returns the strongly connected component (itself a DirectedGraph) # that includes <node>. DiGraph#strongly_connected_component_including_node(node)
Any Ruby object can be a node in a graph and you create graphs by giving
number of edges. Each edge is an Array with maximum two nodes where the
node is the source node.
The quiz has two phases: first a black-box phase and then a white-box
the black-box phase you do not have access to the source code but do
testing over the network via drb. When you are satisfied with your tests
this phase you submit them, get the source code and start the white-box
Now you can extend your test suite given the actual code, fix problems
refactor the code as you see fit (as long as you do not change the
You need to download the file “rubyquiz73.rb” to participate in the
After downloading and saving that file, here is how you get a reference
class under test (CUT):
require 'test/unit' require 'rubyquiz73' # You must insert your email address as <youremail> in this method
DiGraph = RubyQuiz73.class_under_test("")
class TestDiGraph < Test::Unit::TestCase def test_01_digraph_creation dg1 = DiGraph.new assert_kind_of(DiGraph, dg1) assert_equal(0, dg1.size) end def test_02_size dg2 = DiGraph.new([1,2], [2,3]) assert_equal(3, dg2.size) assert_equal(2, dg2.num_edges) end # Add/write your own tests here... end
Note that since we use drb for the distributed testing and we had to
performance trade-offs not every assertion or code might work exactly as
would if run locally. However, most “normal” things will work.
When you consider yourself ready with the blackbox phase of the testing
should submit your test suite. You do this by issuing the command:
ruby rubyquiz73.rb submit1 <test_filename.rb>
and giving the path to your test file. The script will get back the
for the class being tested and save it. You can now look at the source
add tests as you see fit. You can also alter and refactor the source
long as you do not change the interface. When you are done with this,
phase, you submit your test file and source file like so (you can add
files if you have split your tests over several files):
ruby rubyquiz73.rb submit2 <test_filename.rb> <src_filename.rb>
[Editor’s Note: Please also send in your tests to Ruby T., after the
period, for use in the summary. --JEG2]
You can also get some help information by issuing:
ruby rubyquiz73.rb help
You are encouraged to briefly document (in comments or by other means)
why you arrived at and included the test cases you’ve chosen and why you
your tests are thorough. You are also encouraged to add tests for
methods of the DiGraph class as you see fit. Note that the devious
Manager has not eliminated all problems with the given code so you are
to find problems/faults!
If the specifications in the RDoc comments above are not complete enough
please make additional, sound assumptions and make them clear in your