tests/TestDirectedGraph.rb in rgl-0.2.2 vs tests/TestDirectedGraph.rb in rgl-0.2.3

- old
+ new

@@ -12,12 +12,12 @@ end end def test_empty_graph dg = DirectedAdjacencyGraph.new - assert(dg.empty?) - assert(dg.directed?) + assert dg.empty? + assert dg.directed? assert(!dg.has_edge?(2,1)) assert(!dg.has_vertex?(3)) # Non existend vertex result in a Name Error because each_key is # called for nil assert_raises(NoVertexError) {dg.out_degree(3)} @@ -94,7 +94,27 @@ def test_creating_from_array dg = DirectedAdjacencyGraph[1, 2, 3, 4] assert_equal(dg.vertices.sort, [1,2,3,4]) assert_equal(dg.edges.to_s, "(1-2)(3-4)") + end + + def test_reverse + reverted = @dg.reverse + @dg.each_edge do |u,v| + assert(reverted.has_edge?(v,u)) + end + end + + def test_reverse + # Add isolated vertex + @dg.add_vertex(42) + reverted = @dg.reverse + + @dg.each_edge do |u,v| + assert(reverted.has_edge?(v,u)) + end + + assert(reverted.has_vertex?(42), + "Reverted graph should contain isolated Vertex 42") end end