diff --git a/test/tc_adj_to_distance.rb b/test/tc_adj_to_distance.rb new file mode 100644 index 0000000..9ec60b5 --- /dev/null +++ b/test/tc_adj_to_distance.rb @@ -0,0 +1,24 @@ +require 'igraph' + +g = IGraph.new(['A','B','A','C','A','D','C','D'],false) + +adj = g.get_adjacency(2) +g.vcount.times do |k| + adj[k][k] = 1 +end + +dis = Array.new(4){|i| Array.new(4)} + +dis.each_with_index do |row,i| + row.each_with_index do |cell,j| + cij = 0 + g.vcount.times do |k| + puts "#{i} #{j} #{k}" + cij += adj[i][k] * adj[j][k] + end + dis[i][j] = 10 - cij + end +end + +p adj +p dis diff --git a/test/tc_dijkstra.rb b/test/tc_dijkstra.rb new file mode 100644 index 0000000..cc840f9 --- /dev/null +++ b/test/tc_dijkstra.rb @@ -0,0 +1,11 @@ +require 'test/unit' +require 'igraph' + +Infinity = 1.0/0 + +class TestGraph < Test::Unit::TestCase + def test_dijkstra + g = IGraph.new([1,2,3,4],false) + assert_equal [[0,1.5,Infinity,Infinity]], g.dijkstra_shortest_paths([1],[1.5,2.5],IGraph::OUT) + end + end diff --git a/test/tc_independent_vertex_sets.rb b/test/tc_independent_vertex_sets.rb new file mode 100644 index 0000000..5f576c1 --- /dev/null +++ b/test/tc_independent_vertex_sets.rb @@ -0,0 +1,21 @@ +require 'test/unit' +require 'igraph' + +class TestGraph < Test::Unit::TestCase + def test_independent_vertex_sets + g = IGraph.new([1,2,3,4],true) + assert_equal [[1,3],[1,4],[2,3],[2,4]], g.independent_vertex_sets(2,0) + end + def test_largest_independent_vertex_sets + g = IGraph.new([1,2,3,4,1,5],true) + assert_equal [[2,3,5],[2,4,5]], g.largest_independent_vertex_sets + end + def test_maximal_independent_vertex_sets + g = IGraph.new([1,2,3,4],true) + assert_equal [[1,3],[1,4],[2,3],[2,4]], g.maximal_independent_vertex_sets + end + def test_independence_number + g = IGraph.new([1,2,3,4],true) + assert_equal 2, g.independence_number + end +end diff --git a/test/tc_isomorphic.rb b/test/tc_isomorphic.rb new file mode 100644 index 0000000..b9f097e --- /dev/null +++ b/test/tc_isomorphic.rb @@ -0,0 +1,33 @@ +require 'test/unit' +require 'igraph' + +class TestGraph < Test::Unit::TestCase + def test_isomorphic + g = IGraph.new([1,2,3,4],false) + h = IGraph.new([5,6,7,8],false) + assert_equal true, g.isomorphic(h) + assert_equal true, h.isomorphic(g) + end + def test_isomorphic_vf2 + g = IGraph.new([1,2,3,4],false) + h = IGraph.new([5,6,7,8],false) + assert_equal true, g.isomorphic_vf2(h) + assert_equal true, h.isomorphic_vf2(g) + end + def test_isoclass + g = IGraph.new([1,2,3,4],false) + h = IGraph.new([5,6,7,8],false) + assert g.isoclass >= 0 and g.isoclass <= 11 + assert_equal h.isoclass, g.isoclass + end + def test_isoclass_subgraph + g = IGraph.new([1,2,3,4],false) + assert g.isoclass_subgraph([1,2,3]) >= 0 and g.isoclass <= 4 + assert_equal g.isoclass_subgraph([1,2,3]), g.isoclass_subgraph([2,3,4]) + end + def test_igraph_isoclass_create + g = IGraph.new([1,2,3,4],false) + h = IGraph.isoclass_create(4,g.isoclass,false) + assert_equal g.isoclass, h.isoclass + end +end diff --git a/test/tc_motif.rb b/test/tc_motif.rb new file mode 100644 index 0000000..c30212f --- /dev/null +++ b/test/tc_motif.rb @@ -0,0 +1,19 @@ +require 'test/unit' +require 'igraph' + +class TestGraph < Test::Unit::TestCase + def test_motifs_randesu + g = IGraph.new(['A','B','C','D','A','C'],false) + hist = g.motifs_randesu(3,[0,0,0]) + assert_equal [0,0,2,0], hist + end + def test_motifs_randesu_no + g = IGraph.new(['A','B','C','D','A','C'],false) + assert_equal 2, g.motifs_randesu_no(3,[0,0,0]) + end + def test_motifs_randesu_estimate + g = IGraph.new(['A','B','C','D','A','C'],false) + assert_equal 2, g.motifs_randesu_estimate(3,[0,0,0],4,nil) + assert_equal 2, g.motifs_randesu_estimate(3,[0,0,0],0,['A','B','C','D']) + end +end