Kouhei Sutou
null+****@clear*****
Sun Feb 21 19:34:21 JST 2016
Kouhei Sutou 2016-02-21 19:34:21 +0900 (Sun, 21 Feb 2016) New Revision: 9f2f8c337a1f0df609afa25efb2a21f65d3cf21a https://github.com/ranguba/rroonga/commit/9f2f8c337a1f0df609afa25efb2a21f65d3cf21a Message: Accept integer and time as function call arguments Modified files: lib/groonga/expression-builder.rb test/test-expression-builder.rb Modified: lib/groonga/expression-builder.rb (+1 -1) =================================================================== --- lib/groonga/expression-builder.rb 2016-02-21 16:41:16 +0900 (504a394) +++ lib/groonga/expression-builder.rb 2016-02-21 19:34:21 +0900 (2c42e1a) @@ -476,7 +476,7 @@ module Groonga expression.append_object(@function) @arguments.each do |argument| case argument - when String + when String, Integer, Time expression.append_constant(argument) else argument.build(expression, variable) Modified: test/test-expression-builder.rb (+106 -24) =================================================================== --- test/test-expression-builder.rb 2016-02-21 16:41:16 +0900 (fc7de26) +++ test/test-expression-builder.rb 2016-02-21 19:34:21 +0900 (ecbf30e) @@ -532,39 +532,121 @@ EOC end class CallTest < self - def setup_tables - Groonga::Schema.define do |schema| - schema.create_table("Shops", - :type => :hash, - :key_type => "ShortText") do |table| - table.wgs84_geo_point("location") - end + class StringTest < self + def setup_tables + Groonga::Schema.define do |schema| + schema.create_table("Shops", + :type => :hash, + :key_type => "ShortText") do |table| + table.wgs84_geo_point("location") + end - schema.create_table("Locations", - :type => :patricia_trie, - :key_type => :wgs84_geo_point) do |table| - table.index("Shops.location") + schema.create_table("Locations", + :type => :patricia_trie, + :key_type => :wgs84_geo_point) do |table| + table.index("Shops.location") + end end + + @shops = Groonga["Shops"] end - @shops = Groonga["Shops"] + def setup_data + @shops.add("Nezu no taiyaki", :location => "35.720253,139.762573") + @shops.add("Taiyaki Kataoka", :location => "35.712521,139.715591") + @shops.add("Taiyaki Sharaku", :location => "35.716969,139.794846") + end + + def test_search + result =****@shops***** do |record| + record.call("geo_in_rectangle", + record.location, + "35.7185,139.7912", + "35.7065,139.8069") + end + assert_equal(["Taiyaki Sharaku"], + result.collect(&:_key)) + end end - def setup_data - @shops.add("Nezu no taiyaki", :location => "35.720253,139.762573") - @shops.add("Taiyaki Kataoka", :location => "35.712521,139.715591") - @shops.add("Taiyaki Sharaku", :location => "35.716969,139.794846") + class IntegerTest < self + def setup_tables + Groonga::Schema.define do |schema| + schema.create_table("Users", + :type => :hash, + :key_type => "ShortText") do |table| + table.int32("age") + end + + schema.create_table("Ages", + :type => :patricia_trie, + :key_type => :int32) do |table| + table.index("Users.age") + end + end + + @users = Groonga["Users"] + end + + def setup_data + @users.add("Alice", :age => 18) + @users.add("Bob", :age => 29) + @users.add("Carlos", :age => 14) + end + + def test_search + result =****@users***** do |record| + record.call("between", + record.age, + 18, + "include", + 29, + "exclude") + end + assert_equal(["Alice"], + result.collect(&:_key)) + end end - def test_search - result =****@shops***** do |record| - record.call("geo_in_rectangle", - record.location, - "35.7185,139.7912", - "35.7065,139.8069") + class TimeTest < self + def setup_tables + Groonga::Schema.define do |schema| + schema.create_table("Logs", + :type => :array) do |table| + table.time("timestamp") + end + + schema.create_table("Times", + :type => :patricia_trie, + :key_type => :time) do |table| + table.index("Logs.timestamp") + end + end + + @logs = Groonga["Logs"] + end + + def setup_data + @logs.add(:timestamp => Time.iso8601("2016-02-21T19:00:01Z")) + @logs.add(:timestamp => Time.iso8601("2016-02-21T19:00:02Z")) + @logs.add(:timestamp => Time.iso8601("2016-02-21T19:00:03Z")) + end + + def test_search + result =****@logs***** do |record| + record.call("between", + record.timestamp, + Time.iso8601("2016-02-21T19:00:01Z"), + "include", + Time.iso8601("2016-02-21T19:00:03Z"), + "exclude") + end + assert_equal([ + Time.iso8601("2016-02-21T19:00:01Z"), + Time.iso8601("2016-02-21T19:00:02Z"), + ], + result.collect(&:timestamp)) end - assert_equal(["Taiyaki Sharaku"], - result.collect(&:_key)) end end -------------- next part -------------- HTML����������������������������... 下載