Navigation Menu

Skip to content

Commit

Permalink
response-comparer: support drilldown
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 13, 2018
1 parent c7709d5 commit e16f2d6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
36 changes: 27 additions & 9 deletions lib/groonga-query-log/response-comparer.rb
Expand Up @@ -61,12 +61,13 @@ def same_response?
def same_select_response?
if care_order?
if all_output_columns?
same_records_all_output_columns?
return false unless same_records_all_output_columns?
elsif have_unary_minus_output_column?
same_records_unary_minus_output_column?
return false unless same_records_unary_minus_output_column?
else
same_records?
return false unless same_records?
end
same_drilldowns?
else
same_size_response?
end
Expand Down Expand Up @@ -212,16 +213,21 @@ def same_records?
records_result2 = @response2.body[0] || []
return false if records_result1.size != records_result2.size

n_hits1 = records_result1[0]
n_hits2 = records_result2[0]
same_record_set(records_result1,
records_result2)
end

def same_record_set?(record_set1, record_set2)
n_hits1 = record_set1[0]
n_hits2 = record_set2[0]
return false if n_hits1 != n_hits2

columns1 = records_result1[1]
columns2 = records_result2[1]
columns1 = record_set1[1]
columns2 = record_set2[1]
return false if columns1 != columns2

records1 = records_result1[2..-1]
records2 = records_result2[2..-1]
records1 = record_set1[2..-1]
records2 = record_set2[2..-1]
records1.each_with_index do |record1, record_index|
record2 = records2[record_index]
columns1.each_with_index do |column1, column_index|
Expand All @@ -244,6 +250,18 @@ def make_column_to_index_map(columns)
map
end

def same_drilldowns?
drilldowns1 = @response1.body[1..-1] || []
drilldowns2 = @response2.body[1..-1] || []
return false if drilldowns1.size != drilldowns2.size

drilldowns1.each_with_index do |drilldown1, drilldown_index|
drilldown2 = drilldowns2[drilldown_index]
return false unless same_record_set?(drilldown1, drilldown2)
end
true
end

def normalize_value(value, column)
type = column[1]
case type
Expand Down
32 changes: 32 additions & 0 deletions test/test-response-comparer.rb
Expand Up @@ -363,6 +363,38 @@ def test_specific_output_columns
end
end

class DrilldownTest < self
def create_response(drilldown)
[
[
[10],
[["_id", "UInt32"]],
],
[
[drilldown.size * 2],
[["_key", "ShortText"], ["_nsubrecs", "Int32"]],
*drilldown,
]
]
end

def test_same
response1 = create_response([["A", 10], ["B", 2]])
response2 = create_response([["A", 10], ["B", 2]])
assert do
same?(response1, response2)
end
end

def test_not_same
response1 = create_response([["A", 11], ["B", 2]])
response2 = create_response([["A", 10], ["B", 2]])
assert do
not same?(response1, response2)
end
end
end

class ErrorTest < self
def test_with_location
response1_header = [
Expand Down

0 comments on commit e16f2d6

Please sign in to comment.