[Groonga-commit] droonga/droonga-message-pack-packer-ruby at 5c1ccb9 [master] Add tests for geo point

Back to archive index

Kouhei Sutou null+****@clear*****
Mon May 26 18:21:41 JST 2014


Kouhei Sutou	2014-05-26 18:21:41 +0900 (Mon, 26 May 2014)

  New Revision: 5c1ccb9bc1a76564f46ec569e09a157eb9a117ad
  https://github.com/droonga/droonga-message-pack-packer-ruby/commit/5c1ccb9bc1a76564f46ec569e09a157eb9a117ad

  Message:
    Add tests for geo point

  Added files:
    test/test-geo-point-formatter.rb
  Modified files:
    test/test-packer.rb

  Added: test/test-geo-point-formatter.rb (+41 -0) 100644
===================================================================
--- /dev/null
+++ test/test-geo-point-formatter.rb    2014-05-26 18:21:41 +0900 (e3fda17)
@@ -0,0 +1,41 @@
+# Copyright (C) 2014 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require "droonga/message-pack-packer/geo-point-formatter"
+
+class GeoPointFormatterTest < Test::Unit::TestCase
+  def test_format
+    geo_point_class = Class.new do
+      def initialize(latitude, longitude)
+        @latitude = latitude
+        @longitude = longitude
+      end
+
+      def to_s
+        "<#{@latitude}x#{@longitude}>"
+      end
+    end
+
+    latitude = 35.681382
+    longitude = 139.766084
+    tokyo = geo_point_class.new(latitude, longitude)
+    assert_equal("<#{latitude}x#{longitude}>", format(tokyo))
+  end
+
+  private
+  def format(geo_point)
+    Droonga::MessagePackPacker::GeoPointFormatter.format(geo_point)
+  end
+end

  Modified: test/test-packer.rb (+48 -0)
===================================================================
--- test/test-packer.rb    2014-05-26 17:58:05 +0900 (10b7b5b)
+++ test/test-packer.rb    2014-05-26 18:21:41 +0900 (2180ba7)
@@ -40,6 +40,54 @@ class PackerTest < Test::Unit::TestCase
     assert_equal(array, unpack(pack(array)))
   end
 
+  def test_wgs84_geo_point
+    wgs84_geo_point_class = Class.new do
+      class << self
+        def name
+          "Groonga::WGS84GeoPoint"
+        end
+      end
+
+      def initialize(latitude, longitude)
+        @latitude = latitude
+        @longitude = longitude
+      end
+
+      def to_s
+        "<#{@latitude}x#{@longitude}>"
+      end
+    end
+
+    latitude = 35.681382
+    longitude = 139.766084
+    tokyo = wgs84_geo_point_class.new(latitude, longitude)
+    assert_equal("<#{latitude}x#{longitude}>", unpack(pack(tokyo)))
+  end
+
+  def test_tokyo_geo_point
+    tokyo_geo_point_class = Class.new do
+      class << self
+        def name
+          "Groonga::TokyoGeoPoint"
+        end
+      end
+
+      def initialize(latitude, longitude)
+        @latitude = latitude
+        @longitude = longitude
+      end
+
+      def to_s
+        "<#{@latitude}x#{@longitude}>"
+      end
+    end
+
+    latitude = 35.681382
+    longitude = 139.766084
+    tokyo = tokyo_geo_point_class.new(latitude, longitude)
+    assert_equal("<#{latitude}x#{longitude}>", unpack(pack(tokyo)))
+  end
+
   private
   def pack(object)
     Droonga::MessagePackPacker.pack(object)
-------------- next part --------------
HTML����������������������������...
下載 



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