Navigation Menu

Skip to content

Commit

Permalink
response-comparer: support specific output columns case
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 12, 2018
1 parent 8d64324 commit 9b8e890
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/groonga-query-log/response-comparer.rb
Expand Up @@ -65,7 +65,7 @@ def same_select_response?
elsif have_unary_minus_output_column?
same_records_unary_minus_output_column?
else
same_response?
same_records?
end
else
same_size_response?
Expand Down Expand Up @@ -207,6 +207,35 @@ def same_records_all_output_columns?
true
end

def same_records?
records_result1 = @response1.body[0] || []
records_result2 = @response2.body[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 != columns2

records1 = records_result1[2..-1]
records2 = records_result2[2..-1]
records1.each_with_index do |record1, record_index|
record2 = records2[record_index]
columns1.each_with_index do |column1, column_index|
value1 = record1[column_index]
value1 = normalize_value(value1, column1)
value2 = record2[column_index]
value2 = normalize_value(value2, column1)
return false if value1 != value2
end
end

true
end

def make_column_to_index_map(columns)
map = {}
columns.each_with_index do |(name, _), i|
Expand Down
9 changes: 9 additions & 0 deletions test/test-response-comparer.rb
Expand Up @@ -333,6 +333,15 @@ def test_unary_minus_output_column
same?(response1, response2)
end
end

def test_specific_output_columns
@command["output_columns"] = "_id, latitude, longitude"
response1 = create_response(35.6562002690605, 139.763570507358)
response2 = create_response(35.65620026906051, 139.7635705073576)
assert do
same?(response1, response2)
end
end
end

class ErrorTest < self
Expand Down

0 comments on commit 9b8e890

Please sign in to comment.