[Groonga-commit] groonga/groonga-query-log at c3319a5 [master] response-comparer: support all output case

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jun 12 17:34:45 JST 2018


Kouhei Sutou	2018-06-12 17:34:45 +0900 (Tue, 12 Jun 2018)

  New Revision: c3319a5b69fe9cbb353264940dd32557f7b823ee
  https://github.com/groonga/groonga-query-log/commit/c3319a5b69fe9cbb353264940dd32557f7b823ee

  Message:
    response-comparer: support all output case
    
    We don't need to normalize float value when no care order mode because
    we just check response size in the mode.

  Modified files:
    lib/groonga-query-log/response-comparer.rb
    test/test-response-comparer.rb

  Modified: lib/groonga-query-log/response-comparer.rb (+15 -19)
===================================================================
--- lib/groonga-query-log/response-comparer.rb    2018-06-12 17:26:27 +0900 (df8e657)
+++ lib/groonga-query-log/response-comparer.rb    2018-06-12 17:34:45 +0900 (dc30556)
@@ -68,11 +68,7 @@ module GroongaQueryLog
           same_response?
         end
       else
-        if same_location_information?
-          same_size_response?
-        else
-          false
-        end
+        same_size_response?
       end
     end
 
@@ -124,19 +120,6 @@ module GroongaQueryLog
       end
     end
 
-    def same_location_information?
-      if****@respo*****[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 =****@comma*****_columns
       return false if output_columns.nil?
@@ -211,7 +194,10 @@ module GroongaQueryLog
         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
@@ -226,5 +212,15 @@ module GroongaQueryLog
       end
       map
     end
+
+    def normalize_value(value, column)
+      type = column[1]
+      case type
+      when "Float"
+        value.round(12)
+      else
+        value
+      end
+    end
   end
 end

  Modified: test/test-response-comparer.rb (+8 -8)
===================================================================
--- test/test-response-comparer.rb    2018-06-12 17:26:27 +0900 (51eba8c)
+++ test/test-response-comparer.rb    2018-06-12 17:34:45 +0900 (19b77b9)
@@ -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
@@ -307,21 +307,21 @@ class ResponseComparerTest < Test::Unit::TestCase
     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
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180612/be5c05bc/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index