Unit Testing in Ruby

Overview

This activity will provide you the experience of both completing the implementation of a Ruby class and creating appropriate unit tests for the class. The example we will use is a simple directed graph, where vertices are represented by strings and each vertex has an array holding the names of its directly connected neighbor vertices.

The Activity

  1. Download DiGraph.rb and DiGraphTest.rb.
  2. DiGraph implements the directed graph structure by maintaining a Hash that maps each known vertex to an array containing that vertex's directly connected neighbors. It is perfectly legal for a vertex to have no neighbors (an empty array). No vertex may list a neighbor more than once. If you need to brush up on graphs, especially those represented by adjacency lists such as ours, consult this PDF file on graphs.
  3. Add tests to DiGraphTest.rb to test all the provided methods in DiGraph.rb. Fix any errors your tests uncover in the implementation.
  4. Implement the three skeleton methods in DiGraph.rb (near the end of the file).
  5. Add tests to DiGraphTest.rb to test your implemented methods.

Submission

Submit DiGraph.rb and DiGraphTest.rb - to a directory named DiGraph in your git repo.

Examples:

Here is the source from the Queue & Unit Tests for Queue used in the Ruby Unit Testing slides:

queue.rb
test_queue.rb