Kouhei Sutou
null+****@clear*****
Tue Jun 12 09:52:13 JST 2018
Kouhei Sutou 2018-06-12 09:52:13 +0900 (Tue, 12 Jun 2018) New Revision: 80a571f005b6178cea67542476488f3f315aed3f https://github.com/groonga/groonga-query-log/commit/80a571f005b6178cea67542476488f3f315aed3f Message: Fix indent Modified files: lib/groonga-query-log/response-comparer.rb Modified: lib/groonga-query-log/response-comparer.rb (+157 -157) =================================================================== --- lib/groonga-query-log/response-comparer.rb 2018-06-11 15:19:23 +0900 (91320d2) +++ lib/groonga-query-log/response-comparer.rb 2018-06-12 09:52:13 +0900 (2ac724f) @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2017 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2014-2018 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -15,199 +15,199 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA module GroongaQueryLog - class ResponseComparer - def initialize(command, response1, response2, options={}) - @command = command - @response1 = response1 - @response2 = response2 - @options = options - @options[:care_order] = true if @options[:care_order].nil? - end + class ResponseComparer + def initialize(command, response1, response2, options={}) + @command = command + @response1 = response1 + @response2 = response2 + @options = options + @options[:care_order] = true if @options[:care_order].nil? + end - def same? - if error_response?(@response1) or error_response?(@response2) - if error_response?(@response1) and error_response?(@response2) - same_error_response? - else - false - end + def same? + if error_response?(@response1) or error_response?(@response2) + if error_response?(@response1) and error_response?(@response2) + same_error_response? else - case****@comma***** - when "select", "logical_select" - same_select_response? - when "status" - same_cache_hit_rate? - else - same_response? - end + false + end + else + case****@comma***** + when "select", "logical_select" + same_select_response? + when "status" + same_cache_hit_rate? + else + same_response? end end + end - private - def error_response?(response) - response.is_a?(Groonga::Client::Response::Error) - end + private + def error_response?(response) + response.is_a?(Groonga::Client::Response::Error) + end - def same_error_response? - return_code1 =****@respo*****[0] - return_code2 =****@respo*****[0] - return_code1 == return_code2 - end + def same_error_response? + return_code1 =****@respo*****[0] + return_code2 =****@respo*****[0] + return_code1 == return_code2 + end - def same_response? - @response1.body ==****@respo***** - end + def same_response? + @response1.body ==****@respo***** + end - def same_select_response? - if care_order? - if all_output_columns? - same_records_all_output_columns? - elsif have_unary_minus_output_column? - same_records_unary_minus_output_column? - else - same_response? - end + def same_select_response? + if care_order? + if all_output_columns? + same_records_all_output_columns? + elsif have_unary_minus_output_column? + same_records_unary_minus_output_column? else - same_size_response? + same_response? end + else + same_size_response? end + end - def same_cache_hit_rate? - cache_hit_rate1 =****@respo*****["cache_hit_rate"] - cache_hit_rate2 =****@respo*****["cache_hit_rate"] - (cache_hit_rate1 - cache_hit_rate2).abs < (10 ** -13) - end + def same_cache_hit_rate? + cache_hit_rate1 =****@respo*****["cache_hit_rate"] + cache_hit_rate2 =****@respo*****["cache_hit_rate"] + (cache_hit_rate1 - cache_hit_rate2).abs < (10 ** -13) + end - def care_order? - return false unless @options[:care_order] - return false if random_sort? + def care_order? + return false unless @options[:care_order] + return false if random_sort? - true - end + true + end - def random_score? - return false unles****@comma*****_to?(:scorer) - /\A_score\s*=\s*rand\(\)\z/ ===****@comma***** - end + def random_score? + return false unles****@comma*****_to?(:scorer) + /\A_score\s*=\s*rand\(\)\z/ ===****@comma***** + end - def random_sort? - random_score? and score_sort? - end + def random_sort? + random_score? and score_sort? + end - def score_sort? - sort_items = (@command.sortby || "").split(/\s*,\s*/) - normalized_sort_items = sort_items.collect do |item| - item.gsub(/\A[+-]/, "") - end - normalized_sort_items.include?("_score") + def score_sort? + sort_items = (@command.sortby || "").split(/\s*,\s*/) + normalized_sort_items = sort_items.collect do |item| + item.gsub(/\A[+-]/, "") end + normalized_sort_items.include?("_score") + end - def same_size_response? - records_result1 =****@respo*****[0] || [] - records_result2 =****@respo*****[0] || [] - return false if records_result1.size != records_result2.size + def same_size_response? + records_result1 =****@respo*****[0] || [] + records_result2 =****@respo*****[0] || [] + return false if records_result1.size != records_result2.size - n_hits1 = records_result1[0] - n_hits2 = records_result2[0] - return false if n_hits1 != n_hits2 + n_hits1 = records_result1[0] + n_hits2 = records_result2[0] + return false if n_hits1 != n_hits2 - columns1 = records_result1[1] - columns2 = records_result2[1] - if all_output_columns? - columns1.sort_by(&:first) == columns2.sort_by(&:first) - else - columns1 == columns2 - end + columns1 = records_result1[1] + columns2 = records_result2[1] + if all_output_columns? + columns1.sort_by(&:first) == columns2.sort_by(&:first) + else + columns1 == columns2 end + end - def have_unary_minus_output_column? - output_columns =****@comma*****_columns - return false if output_columns.nil? - output_columns.split(/\s*,?\s*/).any? {|column| column.start_with?("-")} - end + def have_unary_minus_output_column? + output_columns =****@comma*****_columns + return false if output_columns.nil? + output_columns.split(/\s*,?\s*/).any? {|column| column.start_with?("-")} + end - def same_records_unary_minus_output_column? - records_result1 =****@respo*****[0] || [] - records_result2 =****@respo*****[0] || [] - return false if records_result1.size != records_result2.size + def same_records_unary_minus_output_column? + records_result1 =****@respo*****[0] || [] + records_result2 =****@respo*****[0] || [] + return false if records_result1.size != records_result2.size - n_hits1 = records_result1[0] - n_hits2 = records_result2[0] - return false if n_hits1 != n_hits2 + n_hits1 = records_result1[0] + n_hits2 = records_result2[0] + return false if n_hits1 != n_hits2 - columns1 = records_result1[1] - columns2 = records_result2[1] - records1 = records_result1[2..-1] - records2 = records_result2[2..-1] + columns1 = records_result1[1] + columns2 = records_result2[1] + records1 = records_result1[2..-1] + records2 = records_result2[2..-1] - if columns1.size != columns2.size - if columns2.size > columns1.size - columns1, columns2 = columns2, columns1 - records1, records2 = records2, records1 - end + if columns1.size != columns2.size + if columns2.size > columns1.size + columns1, columns2 = columns2, columns1 + records1, records2 = records2, records1 end + end - records1.each_with_index do |record1, record_index| - record2 = records2[record_index] - column_offset2 = 0 - columns1.each_with_index do |name, column_index1| - column_index2 = column_offset2 + column_index1 - if name != columns2[column_index2] - column_offset2 -= 1 - next - end - value1 = record1[column_index1] - value2 = record2[column_index2] - return false if value1 != value2 + records1.each_with_index do |record1, record_index| + record2 = records2[record_index] + column_offset2 = 0 + columns1.each_with_index do |name, column_index1| + column_index2 = column_offset2 + column_index1 + if name != columns2[column_index2] + column_offset2 -= 1 + next end + value1 = record1[column_index1] + value2 = record2[column_index2] + return false if value1 != value2 end - - true end - def all_output_columns? - output_columns =****@comma*****_columns - output_columns.nil? or - /\A\s*\z/ === output_columns or - output_columns.split(/\s*,?\s*/).include?("*") - end + true + end - def same_records_all_output_columns? - records_result1 =****@respo*****[0] || [] - records_result2 =****@respo*****[0] || [] - return false if records_result1.size != records_result2.size - - n_hits1 = records_result1[0] - n_hits2 = records_result2[0] - return false if n_hits1 != n_hits2 - - columns1 = records_result1[1] - columns2 = records_result2[1] - return false if columns1.sort_by(&:first) != columns2.sort_by(&:first) - - column_to_index1 = make_column_to_index_map(columns1) - column_to_index2 = make_column_to_index_map(columns2) - - records1 = records_result1[2..-1] - records2 = records_result2[2..-1] - records1.each_with_index do |record1, record_index| - record2 = records2[record_index] - column_to_index1.each do |name, column_index1| - value1 = record1[column_index1] - value2 = record2[column_to_index2[name]] - return false if value1 != value2 - end - end + def all_output_columns? + output_columns =****@comma*****_columns + output_columns.nil? or + /\A\s*\z/ === output_columns or + output_columns.split(/\s*,?\s*/).include?("*") + end - true + def same_records_all_output_columns? + records_result1 =****@respo*****[0] || [] + records_result2 =****@respo*****[0] || [] + return false if records_result1.size != records_result2.size + + n_hits1 = records_result1[0] + n_hits2 = records_result2[0] + return false if n_hits1 != n_hits2 + + columns1 = records_result1[1] + columns2 = records_result2[1] + return false if columns1.sort_by(&:first) != columns2.sort_by(&:first) + + column_to_index1 = make_column_to_index_map(columns1) + column_to_index2 = make_column_to_index_map(columns2) + + records1 = records_result1[2..-1] + records2 = records_result2[2..-1] + records1.each_with_index do |record1, record_index| + record2 = records2[record_index] + column_to_index1.each do |name, column_index1| + value1 = record1[column_index1] + value2 = record2[column_to_index2[name]] + return false if value1 != value2 + end end - def make_column_to_index_map(columns) - map = {} - columns.each_with_index do |(name, _), i| - map[name] = i - end - map + true + end + + def make_column_to_index_map(columns) + map = {} + columns.each_with_index do |(name, _), i| + map[name] = i end + map end + end end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180612/bea2f04b/attachment-0001.htm