Permalink
Browse files

Solved a false positives problem, after creating specs which demonstr…

…ated it.
  • Loading branch information...
1 parent aefc69c commit 2148419e7793570b6c1f8ffbda7638acc1d7ffbe @gilesbowkett committed Oct 5, 2008
View
@@ -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
View
@@ -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
@@ -0,0 +1,5 @@
+class Post < ActiveRecord::Base
+ def recent
+ find(:all)
+ end
+end
@@ -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
View
@@ -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.