spec/undirected_graph_spec.rb in graphshaper-0.1 vs spec/undirected_graph_spec.rb in graphshaper-0.2
- old
+ new
@@ -1,32 +1,14 @@
require "spec_helper"
-require "stringio" # for testing the logger
describe Graphshaper::UndirectedGraph do
it "should create a graph with a given number of vertices and no edges" do
graph = Graphshaper::UndirectedGraph.new 5
graph.order.should ==(5)
graph.size.should ==(0)
end
- it "should create a graph with a logger for edge creation" do
- edge_creation_logger = StringIO.new
- graph = Graphshaper::UndirectedGraph.new 5, edge_creation_logger: edge_creation_logger
-
- graph.add_edge 1,3
- graph.add_edge 2,3
- edge_creation_logger.string.should ==("1,3\n2,3\n")
- end
-
- it "should create a graph with a logger for vertex creation" do
- vertex_creation_logger = StringIO.new
- graph = Graphshaper::UndirectedGraph.new 5, vertex_creation_logger: vertex_creation_logger
-
- graph.add_vertex
- vertex_creation_logger.string.should ==("0\n1\n2\n3\n4\n5\n")
- end
-
describe "initialized graph" do
before :each do
@graph = Graphshaper::UndirectedGraph.new 5
end
@@ -163,8 +145,35 @@
# One more vertex
@graph.order.should ==(6)
# Two additional edges
@graph.size.should ==(3)
+ end
+ end
+
+ describe "Adapter Support" do
+ before :each do
+ @adapter = double()
+ @adapter.stub :add_vertex
+ @adapter.stub :add_edge
+ end
+
+ it "should tell the adapter about the inital vertices on creation" do
+ 5.times do |vertex_id|
+ @adapter.should_receive(:add_vertex).with(vertex_id)
+ end
+ graph = Graphshaper::UndirectedGraph.new 5, adapters: [@adapter]
+ end
+
+ it "should tell the adapter about later added vertices" do
+ graph = Graphshaper::UndirectedGraph.new 5, adapters: [@adapter]
+ @adapter.should_receive(:add_vertex).with(5)
+ graph.add_vertex
+ end
+
+ it "should tell the adapter about later added edges" do
+ graph = Graphshaper::UndirectedGraph.new 5, adapters: [@adapter]
+ @adapter.should_receive(:add_edge).with(0, 1, 2)
+ graph.add_edge 1, 2
end
end
end
\ No newline at end of file