Navigation Menu

Skip to content

Commit

Permalink
response-comparer: support all output case
Browse files Browse the repository at this point in the history
We don't need to normalize float value when no care order mode because
we just check response size in the mode.
  • Loading branch information
kou committed Jun 12, 2018
1 parent eb22aa3 commit c3319a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
34 changes: 15 additions & 19 deletions lib/groonga-query-log/response-comparer.rb
Expand Up @@ -68,11 +68,7 @@ def same_select_response?
same_response?
end
else
if same_location_information?
same_size_response?
else
false
end
same_size_response?
end
end

Expand Down Expand Up @@ -124,19 +120,6 @@ def same_size_response?
end
end

def same_location_information?
if @response1.body[0][1].flatten.include?("float")
location_information1 =
@response1.body.flatten.select {|e| e.class == Float}
location_information2 =
@response2.body.flatten.select {|e| e.class == Float}

location_information1[0].round(12) == location_information2[0].round(12)
else
true
end
end

def have_unary_minus_output_column?
output_columns = @command.output_columns
return false if output_columns.nil?
Expand Down Expand Up @@ -211,7 +194,10 @@ def same_records_all_output_columns?
record2 = records2[record_index]
column_to_index1.each do |name, column_index1|
value1 = record1[column_index1]
value2 = record2[column_to_index2[name]]
value1 = normalize_value(value1, columns1[column_index1])
column_index2 = column_to_index2[name]
value2 = record2[column_index2]
value2 = normalize_value(value2, columns2[column_index2])
return false if value1 != value2
end
end
Expand All @@ -226,5 +212,15 @@ def make_column_to_index_map(columns)
end
map
end

def normalize_value(value, column)
type = column[1]
case type
when "Float"
value.round(12)
else
value
end
end
end
end
16 changes: 8 additions & 8 deletions test/test-response-comparer.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2014-2016 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
Expand Down Expand Up @@ -307,21 +307,21 @@ def test_different_order
end

class FloatAccurancy < self
def create_response(value)
def create_response(latitude, longitude)
[
[
[1],
[["_id", "UInt32"], ["location", "Float"]],
[1, value],
[["_id", "UInt32"], ["latitude", "Float"], ["longitude", "Float"]],
[1, latitude, longitude],
]
]
end

def test_no_care_order
response1 = create_response(139.763570507358)
response2 = create_response(139.7635705073576)
def test_all_output_columns
response1 = create_response(35.6562002690605, 139.763570507358)
response2 = create_response(35.65620026906051, 139.7635705073576)
assert do
same?(response1, response2, :care_order => false)
same?(response1, response2)
end
end
end
Expand Down

0 comments on commit c3319a5

Please sign in to comment.