diff --git a/Rakefile.rb b/Rakefile.rb index a1d2b2d..a17d227 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -3,7 +3,7 @@ require 'hoe' $LOAD_PATH.unshift("./ext") class IGraph - VERSION = "0.9.0" + VERSION = "0.9.1" end begin diff --git a/ext/cIGraph.c b/ext/cIGraph.c index 774b0f3..9c16aaa 100644 --- a/ext/cIGraph.c +++ b/ext/cIGraph.c @@ -164,6 +164,10 @@ VALUE cIGraph_initialize(int argc, VALUE *argv, VALUE self){ } +VALUE cIGraph_unavailable_method(int argc, VALUE *argv, VALUE self){ + rb_raise(rb_eNoMethodError,"Method not available on OSX"); +} + /* Interface to the iGraph[http://cneurocvs.rmki.kfki.hu/igraph/] library * for graph and network computation. * @@ -449,12 +453,20 @@ void Init_igraph(){ rb_define_method(cIGraph_sorting, "topological_sorting", cIGraph_topological_sorting, 1); /* in cIGraph_topological_sort.c */ - #ifdef __APPLE__ - #else /* Functions for reading graphs from files */ cIGraph_fileread = rb_define_module_under(cIGraph, "FileRead"); rb_include_module(cIGraph, cIGraph_fileread); + #ifdef __APPLE__ + rb_define_singleton_method(cIGraph_fileread, "read_graph_edgelist", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_graphml", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_ncol", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_lgl", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_dimacs", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_graphdb", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_gml", cIGraph_unavailable_method, -1); + rb_define_singleton_method(cIGraph_fileread, "read_graph_pajek", cIGraph_unavailable_method, -1); + #else rb_define_singleton_method(cIGraph_fileread, "read_graph_edgelist", cIGraph_read_graph_edgelist, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_graphml", cIGraph_read_graph_graphml, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_ncol", cIGraph_read_graph_ncol, 5); /* in cIGraph_file.c */ @@ -463,11 +475,21 @@ void Init_igraph(){ rb_define_singleton_method(cIGraph_fileread, "read_graph_graphdb", cIGraph_read_graph_graphdb, 2); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_gml", cIGraph_read_graph_gml, 1); /* in cIGraph_file.c */ rb_define_singleton_method(cIGraph_fileread, "read_graph_pajek", cIGraph_read_graph_pajek, 2); /* in cIGraph_file.c */ - + #endif + /* Functions for writing graphs to files */ cIGraph_filewrite = rb_define_module_under(cIGraph, "FileWrite"); rb_include_module(cIGraph, cIGraph_filewrite); + #ifdef __APPLE__ + rb_define_method(cIGraph_filewrite, "write_graph_edgelist", cIGraph_unavailable_method, -1); + rb_define_method(cIGraph_filewrite, "write_graph_graphml", cIGraph_unavailable_method, -1); + rb_define_method(cIGraph_filewrite, "write_graph_gml", cIGraph_unavailable_method, -1); + rb_define_method(cIGraph_filewrite, "write_graph_ncol", cIGraph_unavailable_method, -1); + rb_define_method(cIGraph_filewrite, "write_graph_lgl", cIGraph_unavailable_method, -1); + rb_define_method(cIGraph_filewrite, "write_graph_dimacs", cIGraph_unavailable_method, -1); + rb_define_method(cIGraph_filewrite, "write_graph_pajek", cIGraph_unavailable_method, -1); + #else rb_define_method(cIGraph_filewrite, "write_graph_edgelist", cIGraph_write_graph_edgelist, 1); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_graphml", cIGraph_write_graph_graphml, 1); /* in cIGraph_file.c */ rb_define_method(cIGraph_filewrite, "write_graph_gml", cIGraph_write_graph_gml, 1); /* in cIGraph_file.c */ @@ -534,7 +556,7 @@ void Init_igraph(){ rb_define_method(cIGraph_community, "community_eb_get_merges", cIGraph_community_eb_get_merges, 1); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_fastgreedy", cIGraph_community_fastgreedy, 0); /* in cIGraph_community.c */ - rb_define_const(cIGraph, "VERSION", rb_str_new2("0.9.0")); + rb_define_const(cIGraph, "VERSION", rb_str_new2("0.9.1")); rb_define_const(cIGraph, "EDGEORDER_ID", INT2NUM(1)); rb_define_const(cIGraph, "EDGEORDER_FROM", INT2NUM(2)); diff --git a/test/tc_file_read_write.rb b/test/tc_file_read_write.rb index 772c340..c49d6d4 100644 --- a/test/tc_file_read_write.rb +++ b/test/tc_file_read_write.rb @@ -1,10 +1,18 @@ require 'test/unit' require 'igraph' require 'stringio' +require 'rbconfig' +include Config class TestGraph < Test::Unit::TestCase def test_edgelist_read g = nil + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_edgelist(StringIO.new("0 1 2 3"),true) + } + return + end assert_nothing_raised{ g = IGraph::FileRead.read_graph_edgelist(StringIO.new("0 1 2 3"),true) } @@ -16,6 +24,12 @@ class TestGraph < Test::Unit::TestCase def test_edgelist_write g = IGraph.new([0,1,2,3]) s = StringIO.new("") + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + g.write_graph_edgelist(s) + } + return + end str = g.write_graph_edgelist(s) s.rewind assert_equal "0 1\n2 3\n", s.read @@ -23,9 +37,16 @@ class TestGraph < Test::Unit::TestCase def test_ncol_read g = nil + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_ncol(StringIO.new("0 1\n2 3\n"),[], + false,false,false) + } + return + end assert_nothing_raised{ g = IGraph::FileRead.read_graph_ncol(StringIO.new("0 1\n2 3\n"),[], - false,false,false) + false,false,false) } assert_instance_of IGraph, g assert_equal 4, g.vcount @@ -33,7 +54,7 @@ class TestGraph < Test::Unit::TestCase assert_nothing_raised{ g = IGraph::FileRead.read_graph_ncol(StringIO.new("A B\nC D\n"),[], - true,false,false) + true,false,false) } assert_instance_of IGraph, g assert_equal 4, g.vcount @@ -52,6 +73,12 @@ class TestGraph < Test::Unit::TestCase def test_ncol_write g = IGraph.new(["A","B","C","D"],true,[1,2]) s = StringIO.new("") + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + g.write_graph_ncol(s,true,true) + } + return + end str = g.write_graph_ncol(s,true,true) s.rewind assert_equal "A B 1.0\nC D 2.0\n", s.read @@ -59,6 +86,12 @@ class TestGraph < Test::Unit::TestCase def test_lgl_read g = nil + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_lgl(StringIO.new("#A\nB\n#C\nD\n")) + } + return + end assert_nothing_raised{ g = IGraph::FileRead.read_graph_lgl(StringIO.new("#A\nB\n#C\nD\n"), false,false) @@ -80,15 +113,27 @@ class TestGraph < Test::Unit::TestCase def test_lgl_write g = IGraph.new(["A","B","C","D"],true,[1,2]) s = StringIO.new("") + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + g.write_graph_lgl(s,true,true,false) + } + return + end str = g.write_graph_lgl(s,true,true,false) s.rewind assert_equal "# A\nB 1.0\n# C\nD 2.0\n", s.read end def test_dimacs_read + s = StringIO.new("c com\np min 4 2\nn 1 s\nn 2 t\na 1 2 1\na 3 4 2\n") g = nil + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_dimacs(s,false) + } + return + end assert_nothing_raised{ - s = StringIO.new("c com\np min 4 2\nn 1 s\nn 2 t\na 1 2 1\na 3 4 2\n") g = IGraph::FileRead.read_graph_dimacs(s, false) } @@ -103,12 +148,24 @@ class TestGraph < Test::Unit::TestCase def test_dimacs_write g = IGraph.new(["A","B","C","D"],true,[1,2]) s = StringIO.new("") + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + g.write_graph_dimacs(s,0,1,[1,2]) + } + return + end str = g.write_graph_dimacs(s,0,1,[1,2]) s.rewind assert_equal "c created by igraph\np max 4 2\nn 1 s\nn 2 t\na 1 2 1\na 3 4 2\n", s.read end def test_graphml_read + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_graphml(StringIO.new(Graphml),0) + } + return + end g = nil g = IGraph::FileRead.read_graph_graphml(StringIO.new(Graphml),0) assert_instance_of IGraph, g @@ -128,12 +185,24 @@ class TestGraph < Test::Unit::TestCase {'eid'=>'e2'}]) g.attributes['date'] = 'Friday' s = StringIO.new("") + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + g.write_graph_graphml(s) + } + return + end str = g.write_graph_graphml(s) s.rewind assert_equal Graphml_out, s.read end def test_gml_read + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_gml(StringIO.new(Gml)) + } + return + end g = IGraph::FileRead.read_graph_gml(StringIO.new(Gml)) assert_instance_of IGraph, g end @@ -148,6 +217,12 @@ class TestGraph < Test::Unit::TestCase {'eid'=>'e2'}]) g.attributes['date'] = 'Friday' s = StringIO.new("") + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + g.write_graph_gml(s) + } + return + end str = g.write_graph_gml(s) s.rewind s = s.read @@ -156,6 +231,12 @@ class TestGraph < Test::Unit::TestCase end def test_pajek_read_write + if CONFIG['host'] =~ /apple/ + assert_raises(NoMethodError){ + IGraph::FileRead.read_graph_pajek(StringIO.new(Pajek),0) + } + return + end g = nil g = IGraph::FileRead.read_graph_pajek(StringIO.new(Pajek),0) assert_instance_of IGraph, g diff --git a/test/test_all.rb b/test/test_all.rb index 4218cea..d91c57d 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -19,11 +19,7 @@ require 'tc_cores' require 'tc_dijkstra' require 'tc_directedness' require 'tc_error_handling' - -unless CONFIG['host'] =~ /apple/ - require 'tc_file_read_write' -end - +require 'tc_file_read_write' require 'tc_generators_deterministic' require 'tc_generators_random' require 'tc_independent_vertex_sets'