Skip to content

Commit

Permalink
Add test for new dot options
Browse files Browse the repository at this point in the history
Fix keyword for dir in edge config and assertion

Fix name for comment quoting tests

Fix name for comment quoting tests

Fix test comment method names
  • Loading branch information
r0ckarong committed Mar 24, 2023
1 parent 5d21f48 commit a18d9e9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
47 changes: 47 additions & 0 deletions test/dot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,51 @@ def graph.vertex_id(v)
end
graph.write_to_graphic_file
end

def test_dot2015_options
graph = RGL::DirectedAdjacencyGraph['a', 'b', 'c', 'd']

graph.set_vertex_options('a', label: 'This is A', penwidth: 3.0)
graph.set_vertex_options('b', label: 'This is B', penwdith: 4.0, tooltip: 'This is the B tooltip')
graph.set_vertex_options('c', shape: 'tab', fontcolor: 'blue')

graph.add_edge('a', 'b')
graph.add_edge('a', 'c')
graph.set_edge_options('a', 'b', style: 'dotted', dir: 'back', headtooltip: "Arrowhead tooltip")
graph.set_edge_options('a', 'c', penwidth: 5, color: 'blue')

get_vertex_setting = proc { |v| graph.vertex_options[v] }
get_edge_setting = proc { |u, v| graph.edge_options[graph.edge_class.new(u, v)] }

# To configure more options, add the respective keys and the proc call
# Then provide the respective key:value to set_vertex_options
# Any hard coded values for a key will be applied to all nodes
vertex_options = {
'label' => get_vertex_setting,
'shape' => get_vertex_setting,
'fontcolor' => get_vertex_setting,
'penwidth' => get_vertex_setting,
'tooltip' => get_vertex_setting
}

# To configure more options, add the respective keys and the proc call
# Then provide the respective key:value to set_edge_options
# Any hard coded values for a key will be applied to all edges
edge_options = {
'label' => get_edge_setting,
'dir' => get_edge_setting,
'color' => get_edge_setting,
'style' => get_edge_setting,
'headtooltip' => get_edge_setting,
'penwidth' => get_edge_setting
}

dot_options = { 'edge' => edge_options, 'vertex' => vertex_options }
dot = graph.to_dot_graph(dot_options).to_s

assert_match(dot, /a \[\n\s*fontsize = 8,\n\s*penwidth = 3.0,\n\s*label = "This is A"\n\s*/)
assert_match(dot, /b \[\n\s*fontsize = 8,\n\s*tooltip = "This is the B tooltip",\n\s*label = "This is B"\n\s*/)
assert_match(dot, /a -> b \[\n\s*dir = back,\n\s*fontsize = 8,\n\s*headtooltip = "Arrowhead tooltip",\n\s*style = dotted\n\s*/)
assert_match(dot, /a -> c \[\n\s*color = blue,\n\s*fontsize = 8,\n\s*penwidth = 5\n\s*/)
end
end
8 changes: 4 additions & 4 deletions test/rdot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_label_quoting
assert_match(dot, /label\s*=\s*<html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html>/)
end

def test_option_quoting
def test_comment_quoting
node = DOT::Node.new({ "name" => "test_name", "comment" => "Comment with spaces" })
dot = node.to_s
assert_match(dot, /comment\s*=\s*"Comment with spaces"/)
Expand Down Expand Up @@ -470,7 +470,7 @@ def test_label_quoting
assert_match(dot, /label\s*=\s*<html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html>/)
end

def test_option_quoting
def test_comment_quoting
node = DOT::Graph.new({ "name" => "test_name", "comment" => "Comment with spaces" })
dot = node.to_s
assert_match(dot, /comment\s*=\s*"Comment with spaces"/)
Expand Down Expand Up @@ -637,7 +637,7 @@ def test_label_quoting
assert_match(dot, /label\s*=\s*<html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html>/)
end

def test_option_quoting
def test_comment_quoting
node = DOT::Digraph.new({ "name" => "test_name", "comment" => "Comment with spaces" })
dot = node.to_s
assert_match(dot, /comment\s*=\s*"Comment with spaces"/)
Expand Down Expand Up @@ -804,7 +804,7 @@ def test_label_quoting
assert_match(dot, /label\s*=\s*<html><head><title>test<\/title><\/head>\n<body>text<\/body><\/html>/)
end

def test_option_quoting
def test_comment_quoting
node = DOT::Subgraph.new({ "name" => "test_name", "comment" => "Comment with spaces" })
dot = node.to_s
assert_match(dot, /comment\s*=\s*"Comment with spaces"/)
Expand Down

0 comments on commit a18d9e9

Please sign in to comment.