[Groonga-commit] groonga/groonga [master] test: generate .expected file when -e option specified

Back to archive index

null+****@clear***** null+****@clear*****
2012年 5月 21日 (月) 18:42:40 JST


HAYASHI Kentaro	2012-05-21 18:42:40 +0900 (Mon, 21 May 2012)

  New Revision: b02bd0fc3df175b4ad25e52f397af2da8aca3d0d

  Log:
    test: generate .expected file when -e option specified

  Modified files:
    test/function/tools/geo/generate-grntest-data.rb

  Modified: test/function/tools/geo/generate-grntest-data.rb (+45 -2)
===================================================================
--- test/function/tools/geo/generate-grntest-data.rb    2012-05-21 13:02:54 +0900 (6e301a3)
+++ test/function/tools/geo/generate-grntest-data.rb    2012-05-21 18:42:40 +0900 (fa1b4e7)
@@ -17,7 +17,7 @@ LOAD_RESULT = "[[0,0.0,0.0],1]\n"
 
 SELECT = "select Geo --output_columns distance "
 
-SELECT_PRE = "[[0,0.0,0.0],[[[1],[[\"_score\",\"Int32\"]],["
+SELECT_PRE = "[[0,0.0,0.0],[[[1],[[\"distance\",\"Int32\"]],["
 SELECT_POST = "]]]]"
 
 class GrnTestData
@@ -414,7 +414,36 @@ class GrnTestData
             SELECT, scorer, select_postfix)
   end
 
+  def geo_distance(app_type)
+    0
+  end
 
+  def generate_expected_data(app_type)
+    select_postfix = ""
+    scorer = sprintf("--scorer 'distance = geo_distance(\"%sx%s\", \"%sx%s\"",
+                     @longitude_start, @latitude_start,
+                     @longitude_end, @latitude_end, app_type)
+    if app_type == ""
+      select_postfix = ")'\n"
+    else
+      select_postfix = ", \"#{app_type}\")'\n"
+    end
+    distance = geo_distance(app_type) unless @distance != ""
+    [
+      TABLE_CREATE,
+      CREATE_RESULT,
+      COLUMN_CREATE,
+      CREATE_RESULT,
+      LOAD,
+      LOAD_RESULT,
+      SELECT,
+      scorer,
+      select_postfix,
+      SELECT_PRE,
+      distance,
+      SELECT_POST
+    ].join
+  end
 end
 
 
@@ -563,7 +592,7 @@ if __FILE__ == $0
         end
       elsif OPTS.has_key?(:csv_data)
         puts(grndata.generate_new_data(line, type_longitude, quadrant, type, filename))
-      elsif OPTS.has_key?(:test)
+      elsif OPTS.has_key?(:test) or OPTS.has_key?(:expected)
         app_types.each do |app_type|
           file_prefix = ""
           if app_type != ""
@@ -592,6 +621,8 @@ if __FILE__ == $0
             FileUtils.mkdir_p(File.dirname(test_name))
           end
 
+          dot_expected = grndata.generate_expected_data(app_type)
+
           if File.exists?(test_name)
             # duplicated?
             puts("Warning! [#{i}] #{test_name} duplicated")
@@ -603,6 +634,18 @@ if __FILE__ == $0
             end
             test_file.puts(dot_test)
           end
+          expected_name = sprintf("%s/%s.expected",
+                                  File.dirname(test_name),
+                                  File.basename(test_name, ".test"))
+          if OPTS.has_key?(:expected)
+            File.open(expected_name, "w+") do |expected_file|
+              if OPTS.has_key?(:verbose)
+                puts(expected_name)
+                puts(dot_expected)
+              end
+              expected_file.puts(dot_expected)
+            end
+          end
         end
       end
     end




Groonga-commit メーリングリストの案内
Back to archive index