test/test_graph.rb in graph-2.8.1 vs test/test_graph.rb in graph-2.8.2

- old
+ new

@@ -107,28 +107,46 @@ graph.label "blah" assert_graph graph, 'label = "blah"', '"a" -> "b"' end + def assert_delete_node name, exp, edges=true + assert_equal 2, graph.nodes.length + assert_equal 2, graph.nodes_order.length + assert_equal %w[a b], graph.nodes.keys.sort + + if edges then + assert_equal 1, graph.edges.length + assert_equal 1, graph.edges_order.length + end + + graph.delete_node name + + assert_equal 1, graph.nodes.length + assert_equal 1, graph.nodes_order.length + assert_equal exp, graph.nodes.keys.sort + assert_equal 0, graph.edges.length + assert_equal 0, graph.edges_order.length + end + def test_delete_node - g = digraph do + @graph = digraph do node "a" node "b" end - assert_equal 2, g.nodes.length - assert_equal 2, g.nodes_order.length - assert_equal %w[a b], g.nodes.keys.sort + assert_delete_node "a", %w[b], false + end - g.delete_node "a" + def test_delete_node_edges_front + assert_delete_node "a", %w[b] + end - assert_equal 1, g.nodes.length - assert_equal 1, g.nodes_order.length - assert_equal %w[b], g.nodes.keys.sort + def test_delete_node_edges_back + assert_delete_node "b", %w[a] end - def test_label_html graph.label "<<B>blah</B>>" assert_graph graph, 'label = <<B>blah</B>>', '"a" -> "b"' end @@ -181,15 +199,15 @@ assert_equal ["rankdir = LR"], graph.graph_attribs end def test_save - util_save "png" + assert_save "png" end def test_save_nil - util_save nil + assert_save nil end def test_shape assert_attribute "shape", "blah", graph.shape("blah") end @@ -267,23 +285,24 @@ assert_graph(graph, g_s, # HACK: indentation is really messy right now '"a" -> "b"') end - def util_save type + def assert_save type path = File.join(Dir.tmpdir, "blah.#{$$}") - $x = nil + actual = expected = false - def graph.system(*args) - $x = args + mc = (class << graph; self; end) + mc.send :define_method, :system do |*args| + actual = args end graph.save(path, type) assert_equal graph.to_s + "\n", File.read("#{path}.dot") expected = ["dot -T#{type} #{path}.dot > #{path}.png"] if type - assert_equal expected, $x + assert_equal expected, actual ensure File.unlink path rescue nil end end