git-svn-id: http://igraph.rubyforge.org/svn/trunk@42 71f48855-0bbf-4aa5-930d-4df415e86613

This commit is contained in:
alexgutteridge 2007-08-31 05:47:07 +00:00
parent 15210e745a
commit 339b002aa3
6 changed files with 0 additions and 158 deletions

View File

@ -1,31 +0,0 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_directed
g = IGraph.new(['A','B','B','C','C','D'],false)
g.to_directed(IGraph::ARBITRARY)
assert g.are_connected?('A','B') || g.are_connected?('B','A')
assert !(g.are_connected?('A','B') && g.are_connected?('B','A'))
g = IGraph.new(['A','B','B','C','C','D'],false)
g.to_directed(IGraph::MUTUAL)
assert g.are_connected?('A','B') && g.are_connected?('B','A')
end
def test_undirected
g = IGraph.new(['A','B','B','A','B','C','C','D'],true)
g.to_undirected(IGraph::EACH)
assert_equal 4, g.ecount
g = IGraph.new(['A','B','B','A','B','C','C','D'],true)
g.to_undirected(IGraph::COLLAPSE)
assert_equal 3, g.ecount
end
end

View File

@ -1,44 +0,0 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_shortest_paths
graph = IGraph.new(['A','B','C','D'],true)
m = graph.shortest_paths(['A'],IGraph::ALL)
assert_equal 1, m[0][1]
assert_equal 0, m[0][0]
assert_equal graph.vcount, m[0].size
assert_equal nil, m[0][2]
end
def test_get_shortest_paths
graph = IGraph.new(['A','B','C','D'],true)
m = graph.get_shortest_paths('A',['B'],IGraph::ALL)
assert_equal ['A','B'], m[0]
#assert_equal [], m[1]
end
def test_get_all_shortest_paths
graph = IGraph.new(['A','B','A','C','B','D','C','D'],true)
m = graph.get_all_shortest_paths('A',['D'],IGraph::ALL)
assert_equal 2, m.length
end
def test_average_path_length
graph = IGraph.new(['A','B','A','C','B','D','C','D'],true)
m = graph.average_path_length(true,true)
assert_equal 1.2, m
end
def test_diameter_girth
graph = IGraph.new(['A','B','A','C','B','D'],true)
m = graph.diameter(true,true)
assert_equal 3, m.length
assert_raises IGraphError do
graph.girth
end
graph = IGraph.new(['A','B','A','C','B','D','C','D'],true)
assert_equal 4, graph.girth.length
end
end

View File

@ -1,33 +0,0 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_closeness
g = IGraph.new(['A','B','B','C','C','D'],true)
assert_equal [0.75], g.closeness(['B'],IGraph::ALL)
end
def test_betweenness
g = IGraph.new(['A','B','B','C','C','D'],true)
assert_equal [0,2], g.betweenness(['A','B'],true)
end
def test_edge_betweenness
g = IGraph.new(['A','B','C','D'],true)
assert_equal [1,1], g.edge_betweenness(true)
end
def test_pagerank
g = IGraph.new(['A','B','C','D','E','B','F','B'],true)
assert_equal 67, (g.pagerank(['B'],true,100,0.01,0.8)[0] * 100).to_i
end
def test_constraint
g = IGraph.new(['A','B','C','D'],true)
assert_equal [1], g.constraint(['A'])
assert_raises IGraphError do
g.constraint(['A'],[3])
end
assert_equal [1], g.constraint(['A'],[2,3])
end
def test_maxdegree
g = IGraph.new(['A','B','C','D','A','E','A','F'],true)
assert_equal 3, g.maxdegree(g.vertices,IGraph::ALL,true)
end
end

View File

@ -1,12 +0,0 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_laplacian
g = IGraph.new(['A','B','C','D'],true)
m = g.laplacian(false)
p m
m = g.laplacian(true)
p m
end
end

View File

@ -1,13 +0,0 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_thrash
g = IGraph.new([],true)
10_000.times do |x|
g.add_vertex(x)
end
assert_equal 10_000, g.vcount
end
end

View File

@ -1,25 +0,0 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_subcomponent
g = IGraph.new([1,2,3,4])
assert_equal [1,2], g.subcomponent(1,IGraph::ALL)
end
def test_subgraph
g = IGraph.new([1,2,3,4])
h = g.subgraph([1,2])
assert_equal 2, h.vcount
assert_equal [1,2], h.vertices
end
def test_clusters
g = IGraph.new([1,2,3,4])
assert_equal 2, g.clusters(IGraph::WEAK).length
assert_equal [1,2], g.clusters(IGraph::WEAK)[0]
end
def test_decompose
g = IGraph.new([1,2,3,4])
assert_equal 2, g.decompose(IGraph::WEAK).length
assert_equal [1,2], g.decompose(IGraph::WEAK)[0].vertices
end
end