Skip to content
Permalink
Browse files

Bugfix: GraphAlgo did not work if the nodes were not connected [#172

…state:resolved]
  • Loading branch information...
andreasronge committed May 25, 2011
1 parent 25e2be0 commit d110e92f5cdf0b00580fb7d7d2d47cd91836b321
Showing with 23 additions and 4 deletions.
  1. +6 −1 CHANGELOG
  2. +2 −1 lib/neo4j/algo/algo.rb
  3. +2 −2 neo4j.gemspec
  4. +13 −0 spec/algo/graph_algo_spec.rb
@@ -1,4 +1,9 @@
== 1.1.0 / 2011-05-13
== 1.1.1 / 2011-06-26
* Made neo4j compatible with rails 3.1.0.rc1 [#170]
* Fix for neo4j-devise [#171]
* BUG: Neo4j::GraphAlgo shortest path does raise exception if two nodes are not connected [#172]

== 1.1.0 / 2011-05-13
* Support for embedding neo4j.rb by providing an already running db instance (#168)
* Neo4j::Rails::Relationships should be ActiveModel compliant (#156)
* Support for incoming relationships in Neo4j::Rails::Model (#157)
@@ -187,7 +187,8 @@ def each(&block) #:nodoc:
if @single && @path_finder_method
execute_algo.send(@path_finder_method).each &block
else
(execute_algo && execute_algo).each &block
traversal = execute_algo
traversal.each &block if traversal
end
end

@@ -29,7 +29,7 @@ It comes included with the Apache Lucene document database.
s.rdoc_options = ["--quiet", "--title", "Neo4j.rb", "--line-numbers", "--main", "README.rdoc", "--inline-source"]

s.add_dependency('orm_adapter', ">= 0.0.3")
s.add_dependency("activemodel", ">= 3.0.0")
s.add_dependency("activemodel", ">= 3.1.0.rc1")
s.add_dependency("will_paginate", ["~>3.0.pre"])
s.add_dependency("railties", ">= 3.0.0")
s.add_dependency("railties", ">= 3.1.0.rc1")
end
@@ -12,6 +12,8 @@
@e = Neo4j::Node.new :name => 'e'
@f = Neo4j::Node.new :name => 'f'
@y = Neo4j::Node.new :name => 'y'
@z = Neo4j::Node.new :name => 'z' # not connected

end

describe "#with_length_paths" do
@@ -33,6 +35,10 @@
Neo4j::Algo.with_length_path(@x,@y).depth(3).should include(@b,@c,@y)
end

it "should not find paths if nodes are not connected" do
Neo4j::Algo.with_length_paths(@x,@z).depth(1).size.should == 0
end

end

describe "#a_star_path" do
@@ -50,6 +56,7 @@
res = Neo4j::Algo.a_star_path(@x,@y).cost_evaluator{|rel,*| rel[:weight]}.estimate_evaluator{|node,goal| 1.0}
res.should include(@x,@b,@c,@y)
end

end


@@ -103,6 +110,7 @@
@x = Neo4j::Node.new :name => 'x'
@a = Neo4j::Node.new :name => 'a'
@y = Neo4j::Node.new :name => 'y'
@z = Neo4j::Node.new :name => 'z'
@x.outgoing(:knows) << @a
@a.outgoing(:knows) << @y
# length 3
@@ -140,6 +148,11 @@
Neo4j::Algo.shortest_path(@x,@y).length.should == 2
end

it "should not find paths if nodes are not connected" do
Neo4j::Algo.shortest_path(@x,@z).to_a.should be_empty
end


end
end

0 comments on commit d110e92

Please sign in to comment.
You can’t perform that action at this time.