Skip to content

Commit

Permalink
Solved a false positives problem, after creating specs which demonstr…
Browse files Browse the repository at this point in the history
…ated it.
  • Loading branch information
gilesbowkett committed Oct 5, 2008
1 parent aefc69c commit 2148419
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/array.rb
Expand Up @@ -12,7 +12,9 @@ def stepwise
end
def comparing_collect
accumulator = [] # collect implementation copied from Rubinius
stepwise {|element1, element2| accumulator << element1 if yield(element1, element2)}
stepwise do |element1, element2|
accumulator << element1 if yield(element1, element2)
end
accumulator.compact
end
end
3 changes: 2 additions & 1 deletion lib/node_analysis.rb
Expand Up @@ -18,7 +18,8 @@ def homonyms
end
def diff(threshold)
@method_definitions.comparing_collect do |method_definition_1, method_definition_2|
threshold >= (method_definition_1.body - method_definition_2.body).size
next if method_definition_1.flatten.size < method_definition_2.flatten.size
threshold >= (method_definition_1.body.flatten - method_definition_2.body.flatten).size
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/diff_false_positives/app/models/post.rb
@@ -0,0 +1,5 @@
class Post < ActiveRecord::Base
def recent
find(:all)
end
end
9 changes: 9 additions & 0 deletions spec/diff_false_positives/app/models/user.rb
@@ -0,0 +1,9 @@
class User < ActiveRecord::Base
def login(credentials)
find(:first, :conditions => ["name = ? and password = ?", credentials[:name], credentials[:password]])
end

def dropdown
find(:all).collect { |u| [u.name, u.name] }
end
end
8 changes: 8 additions & 0 deletions spec/model_spec.rb
Expand Up @@ -152,4 +152,12 @@
@model.parse("spec/two_node_diff")
@model.method_definitions[0].filename.should == "spec/two_node_diff/second_file.rb"
end
it "doesn't return false positives for one-node diffs" do
@model.parse("spec/diff_false_positives")
@model.diff(1).should == []
end
it "doesn't return false positives for five-node diffs" do
@model.parse("spec/diff_false_positives")
@model.diff(5).should == []
end
end

0 comments on commit 2148419

Please sign in to comment.