Sha256: 2c90a27fdf28a503c5b85f1a619b018af5331f38908fb7317791527da1ebc8eb

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

require 'test_helper'

require 'rgl/dot'
require 'rgl/adjacency'

class TestDot < Test::Unit::TestCase

  def assert_match(dot, pattern)
    assert(!(dot =~ pattern).nil?, "#{dot} doesn't match #{pattern}")
  end

  def test_to_dot_digraph
    graph = RGL::DirectedAdjacencyGraph["a", "b"]
    dot   = graph.to_dot_graph.to_s

    first_vertex_id = "a"
    second_vertex_id = "b"

    assert_match(dot, /\{[^}]*\}/) # {...}
    assert_match(dot, /#{first_vertex_id}\s*\[/)  # node 1
    assert_match(dot, /label\s*=\s*a/)            # node 1 label
    assert_match(dot, /#{second_vertex_id}\s*\[/) # node 2
    assert_match(dot, /label\s*=\s*b/)            # node 2 label
    assert_match(dot, /#{first_vertex_id}\s*->\s*#{second_vertex_id}/) # edge
  end

  def test_to_dot_graph
    graph = RGL::AdjacencyGraph["a", "b"]
    def graph.vertex_label(v)
      "label-"+v.to_s
    end

    def graph.vertex_id(v)
      "id-"+v.to_s
    end
    dot = graph.write_to_graphic_file
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rgl-0.5.2 test/dot_test.rb