0.1.1 release tagged.

This commit is contained in:
alexgutteridge 2007-07-05 04:45:16 +00:00
commit b36e49b172
4 changed files with 160 additions and 0 deletions

9
ext/cIGraph_operators.c Normal file
View File

@ -0,0 +1,9 @@
#include "igraph.h"
#include "ruby.h"
#include "cIGraph.h"
VALUE cIGraph_add_op(VALUE self, VALUE graph){
return Qnil;
}

93
ext/cIGraph_selectors.c Normal file
View File

@ -0,0 +1,93 @@
#include "igraph.h"
#include "ruby.h"
#include "cIGraph.h"
/* call-seq:
* graph.vertices -> Array
*
* Returns an Array containing all the vertices in the graph. Also aliased
* to IGraph#all_vertices
*
* Example:
*
* g = IGraph.new([1,2,3,4],true)
* g.vertices #returns [1,2,3,4]
*
*/
VALUE cIGraph_all_v(VALUE self){
igraph_t *graph;
Data_Get_Struct(self, igraph_t, graph);
return rb_funcall(rb_iv_get(self,"@object_ids"),rb_intern("keys"),0);
}
/* call-seq:
* graph.adjacent_vertices(v,mode) -> Array
*
* Returns an Array containing all the vertices in the graph that are
* adjacent to vertex v. mode decides the type of the neighborhood for
* directed graphs. Possible values: IGRAPH_OUT, all vertices to which
* there is a directed edge from vid. IGRAPH_IN, all vertices from which
* there is a directed edge from vid. IGRAPH_ALL, all vertices to which
* or from which there is a directed edge from/to vid. This parameter is
* ignored for undirected graphs.
*
* Example:
*
* g = IGraph.new([1,2,3,4],true)
* g.adjacent_vertices(1,IGraph::ALL) #returns [2]
*
*/
VALUE cIGraph_adj_v(VALUE self, VALUE v, VALUE mode){
igraph_t *graph;
igraph_integer_t pnode;
VALUE adjacent = rb_ary_new();
igraph_neimode_t pmode = NUM2INT(mode);
igraph_vs_t vs;
igraph_vit_t vit;
Data_Get_Struct(self, igraph_t, graph);
pnode = cIGraph_get_vertex_id(self,v);
igraph_vs_adj(&vs,pnode,pmode);
igraph_vit_create(graph, vs, &vit);
while(!IGRAPH_VIT_END(vit)) {
rb_ary_push(adjacent,cIGraph_get_vertex_object(self,IGRAPH_VIT_GET(vit)));
IGRAPH_VIT_NEXT(vit);
}
igraph_vit_destroy(&vit);
igraph_vs_destroy(&vs);
return adjacent;
}
VALUE cIGraph_nonadj_v(VALUE self, VALUE v, VALUE mode){
return Qnil;
}
VALUE cIGraph_all_e(VALUE self, VALUE mode){
return Qnil;
}
VALUE cIGraph_adj_e(VALUE self, VALUE v, VALUE mode){
return Qnil;
}
VALUE cIGraph_nonadj_e(VALUE self, VALUE v, VALUE mode){
return Qnil;
}

44
test/tc_iterators.rb Normal file
View File

@ -0,0 +1,44 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_each_vertex
graph = IGraph.new(['A','B','C','D'],true)
assert_nothing_raised do
graph.each_vertex do |v|
end
end
assert_nothing_raised do
graph.each do |v|
end
end
end
def test_each_edge
graph = IGraph.new(['A','B','C','D'],true)
assert_nothing_raised do
graph.each_edge(IGraph::EDGEORDER_ID) do |v,w|
end
end
assert_nothing_raised do
graph.each_edge_eid(IGraph::EDGEORDER_ID) do |v|
end
end
edges = []
graph.each_edge(IGraph::EDGEORDER_ID){|v,w| edges.push([v,w])}
assert_equal [['A','B'],['C','D']], edges
edges = []
graph.each_edge_eid(IGraph::EDGEORDER_ID){|v| edges.push(v)}
assert_equal [0,1], edges
end
def test_enumerable
graph = IGraph.new(['A','B','C','D'],true)
assert graph.all?{|v| v.kind_of? String}
assert graph.any?{|v| v == 'B'}
assert_equal ['A','B','C','D'], graph.collect{|v| v}
assert graph.detect(Proc.new{true}){|v| }
assert_equal ['A'], graph.find_all{|v| v < 'B'}
end
end

14
test/tc_selectors.rb Normal file
View File

@ -0,0 +1,14 @@
require 'test/unit'
require 'igraph'
class TestGraph < Test::Unit::TestCase
def test_select_all
graph = IGraph.new(['A','B','C','D'],true)
assert_equal ['A','B','C','D'], graph.all_vertices
assert_equal ['A','B','C','D'], graph.vertices
end
def test_adj
graph = IGraph.new(['A','B','C','D'],true)
assert_equal ['B'], graph.adjacent_vertices('A',IGraph::ALL)
end
end