Skip to content
Browse files

Avoid non-corresponding methods being paired together.

  • Loading branch information...
1 parent 04b0793 commit 789cfa344c00b38168082d1f76e9dc31becf69ec @agrimm committed Jun 19, 2011
Showing with 17 additions and 5 deletions.
  1. +10 −5 lib/professor.rb
  2. +7 −0 test/test_professor.rb
View
15 lib/professor.rb
@@ -58,13 +58,18 @@ def initialize(old_rdoc_report, new_rdoc_report)
end
def determine_method_comparisons(old_rdoc_report, new_rdoc_report)
- old_rdoc_method_reports, new_rdoc_method_reports = old_rdoc_report.method_reports, new_rdoc_report.method_reports
- methon_name_order = Hash[old_rdoc_method_reports.each_with_index.map{|report, i| [report.name, i]}]
- sorted_new_rdoc_method_reports = new_rdoc_method_reports.sort_by{|report| methon_name_order.fetch(report.name) { 10000} }
- # FIXME assumption of a one to one mapping of methods
- old_rdoc_method_reports.zip(sorted_new_rdoc_method_reports).map do |old_rdoc_method_report, new_rdoc_method_report|
+ old_rdoc_method_reports, new_rdoc_method_reports = [old_rdoc_report, new_rdoc_report].map(&:method_reports)
+ old_rdoc_method_names, new_rdoc_method_names = [old_rdoc_method_reports, new_rdoc_method_reports].map{|reports| reports.map(&:name)}
+ raise "Assumption broken" unless [old_rdoc_method_names, new_rdoc_method_names].all? {|names| names == names.uniq}
+ method_names = old_rdoc_method_names + (new_rdoc_method_names - old_rdoc_method_names)
+ old_rdoc_method_reports_by_name, new_rdoc_method_reports_by_name = [old_rdoc_method_reports, new_rdoc_method_reports].map {|reports| reports.group_by(&:name)}
+ method_comparisons = method_names.map do |method_name|
+ old_rdoc_method_report = old_rdoc_method_reports_by_name.fetch(method_name) { [] }.first
+ new_rdoc_method_report = new_rdoc_method_reports_by_name.fetch(method_name) { [] }.first
method_comparison = MethodComparison.new(old_rdoc_method_report, new_rdoc_method_report)
+ method_comparison
end
+ method_comparisons
end
def output_comparison(output_filename)
View
7 test/test_professor.rb
@@ -36,4 +36,11 @@ def test_handle_difference_in_method_list
comparison = create_comparison_using_filenames("test/data/basic_sec_with_yaml.txt", "test/data/basic_sec_without_output_yaml.txt")
end
end
+
+ def test_report_correct_values_for_shared_methods
+ comparison = create_comparison_using_filenames("test/data/three_method_basic_profile.txt", "test/data/two_method_basic_profile.txt")
+ method_comparison_report_line = get_report_line(comparison, "Module#module_eval")
+ delta_calls_regexp = /\W0.0+\WModule.module_eval/
+ assert_match delta_calls_regexp, method_comparison_report_line, "Doesn't report correct values for a method with identical statistics in both profiles"
+ end
end

0 comments on commit 789cfa3

Please sign in to comment.
Something went wrong with that request. Please try again.