670d252892cbf0a3d1f6bbc09f0a04915ed61d63
1 require File
.expand_path(File
.dirname(__FILE__
) + '/../spec_helper')
12 let (:g) { Graph
.new
}
13 describe
"#initialize" do
14 it
"creates an empty graph" do
16 g
.edges
.should be_empty
17 g
.vertices
.should be_empty
20 it
"creates a graph with some parameters" do
21 g
= Graph
.new
:value1 => 1, :value2 => "value2", :value3 => :v3
23 g
.value2
.should
== "value2"
24 g
.value3
.should
== :v3
25 g
.value4
.should be_nil
30 describe
"adds attribues" do
31 it
"adds then reports arbitrary attributes" do
38 it
"adds a set of vertices" do
39 g
.vertices
.should be_empty
43 g
.should
have(2).vertices
44 g
.vertices
.should
include(v1
)
45 g
.vertices
.should
include(v2
)
48 it
"adds a set of edges" do
49 g
.edges
.should be_empty
53 g
.should
have(2).edges
54 g
.edges
.should
include(e1
)
55 g
.edges
.should
include(e2
)
58 it
"adds a mixed set of vertices and edges" do
59 g
.vertices
.should be_empty
60 g
.edges
.should be_empty
65 g
<< v1
<< e1
<< v2
<< e2
66 g
.should
have(2).vertices
67 g
.vertices
.should
include(v1
)
68 g
.vertices
.should
include(v2
)
69 g
.should
have(2).edges
70 g
.edges
.should
include(e1
)
71 g
.edges
.should
include(e2
)
74 it
"adds a subclass of Vertex" do
75 g
.vertices
.should be_empty
79 g
.should
have(2).vertices
80 g
.vertices
.should
include(v1
)
81 g
.vertices
.should
include(v2
)
86 it
"adds and records an edge between vertices" do
87 g
.vertices
.should be_empty
88 g
.edges
.should be_empty
89 v1
= Vertex
.new(:name => :v1)
90 v2
= Vertex
.new(:name => :v2)
93 g
.should
have(2).vertices
94 g
.vertices
.should
include(v1
)
95 g
.vertices
.should
include(v2
)
96 g
.should
have(1).edges
100 describe
"product" do
101 it
"finds a product graph of a pair of one-vertex graphs" do
108 product
= g1
.product g2
110 product
.should
have(1).vertices
111 product
.vertices
.first
.g1_vertex
.should
== g1v1
112 product
.vertices
.first
.g2_vertex
.should
== g2v1
113 product
.edges
.should be_empty
116 it
"finds a product graph of a pair of simple graphs" do
119 g1v1
= Vertex
.new(:name => :g1v1)
120 g1v2
= Vertex
.new(:name => :g1v2)
121 g1
.connect(g1v1
, g1v2
)
122 g2v1
= Vertex
.new(:name => :g2v1)
123 g2v2
= Vertex
.new(:name => :g2v2)
124 g2
.connect(g2v1
, g2v2
)
127 pg
.should
have(4).vertices
128 pg
.should
have(2).edges