Kouhei Sutou
null+****@clear*****
Mon May 30 19:26:26 JST 2016
Kouhei Sutou 2016-05-30 19:26:26 +0900 (Mon, 30 May 2016) New Revision: 1e7eacb47907cb1cd2b4f2bf3d6e69fbeec93e68 https://github.com/groonga/groonga-query-log/commit/1e7eacb47907cb1cd2b4f2bf3d6e69fbeec93e68 Message: Use relaxed comparison only when unary minus is detected Modified files: lib/groonga/query-log/response-comparer.rb test/test-response-comparer.rb Modified: lib/groonga/query-log/response-comparer.rb (+10 -2) =================================================================== --- lib/groonga/query-log/response-comparer.rb 2016-05-30 19:19:08 +0900 (4e856c8) +++ lib/groonga/query-log/response-comparer.rb 2016-05-30 19:26:26 +0900 (b4bf597) @@ -61,8 +61,10 @@ module Groonga 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_records? + same_response? end else same_size_response? @@ -111,7 +113,13 @@ module Groonga end end - def same_records? + 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 Modified: test/test-response-comparer.rb (+63 -36) =================================================================== --- test/test-response-comparer.rb 2016-05-30 19:19:08 +0900 (b0e883a) +++ test/test-response-comparer.rb 2016-05-30 19:26:26 +0900 (d802b2e) @@ -232,6 +232,69 @@ class ResponseComparerTest < Test::Unit::TestCase comparer([[[0], []]], [[[0], []]]).send(:all_output_columns?) end end + + class UnaryMinusTest < self + def setup + super + @command["output_columns"] = "_id, -value" + end + + def test_ignore + response1 = [ + [ + [3], + [ + ["_id", "UInt32"], + ], + [1], + [2], + [3], + ], + ] + response2 = [ + [ + [3], + [ + ["_id", "UInt32"], + ["value", nil], + ], + [1, -11], + [2, -12], + [3, -13], + ], + ] + assert do + same?(response1, response2) + end + end + end + + class DetectUnaryMinusTest < self + def test_unary_minus_column_only + assert do + have_unary_minus_output_column?("-value") + end + end + + def test_include_unary_minus_column + assert do + have_unary_minus_output_column?("_id, -value") + end + end + + def test_nonexistent + assert do + not have_unary_minus_output_column?("_id, _key") + end + end + + private + def have_unary_minus_output_column?(output_columns) + @command["output_columns"] = output_columns if output_columns + comparer([[[0], []]], + [[[0], []]]).send(:have_unary_minus_output_column?) + end + end end class ForceNoCareOrderTest < self @@ -263,41 +326,5 @@ class ResponseComparerTest < Test::Unit::TestCase assert_true(same?(response1, response2)) end end - - class RecordsTest < self - def setup - super - @command["output_columns"] = "_id, -value" - end - - def test_more_columns - response1 = [ - [ - [3], - [ - ["_id", "UInt32"], - ], - [1], - [2], - [3], - ], - ] - response2 = [ - [ - [3], - [ - ["_id", "UInt32"], - ["value", nil], - ], - [1, -11], - [2, -12], - [3, -13], - ], - ] - assert do - same?(response1, response2) - end - end - end end end -------------- next part -------------- HTML����������������������������... 下載