Permalink
Browse files

Fix ruby 1.8 error case due to math_error_classes bug

  • Loading branch information...
1 parent 9446d23 commit 9c63ba855978a6d70c73680960a8573674c59fe5 @mnoack mnoack committed Jan 12, 2014
Showing with 16 additions and 6 deletions.
  1. +3 −5 lib/geokit/mappable.rb
  2. +1 −1 test/helper.rb
  3. +12 −0 test/test_mappable.rb
View
@@ -60,12 +60,10 @@ def distance_between_flat(from, to, units)
Math.sqrt(lat_length ** 2 + lng_length ** 2)
end
+ # Ruby 1.9 raises {Math::DomainError}, but it is not defined in Ruby 1.8
def math_error_classes
- error_classes = [Errno::EDOM]
-
- # Ruby 1.9 raises {Math::DomainError}, but it is not defined in Ruby
- # 1.8. Backwards-compatibly rescue both errors.
- error_classes << Math::DomainError if defined?(Math::DomainError)
+ return [Errno::EDOM, Math::DomainError] if defined?(Math::DomainError)
+ [Errno::EDOM]
end
# Returns heading in degrees (0 is north, 90 is east, 180 is south, etc)
View
@@ -11,7 +11,7 @@
require 'geoip'
if ENV['COVERAGE']
- COVERAGE_THRESHOLD = 90
+ COVERAGE_THRESHOLD = 91
require 'simplecov'
require 'simplecov-rcov'
require 'coveralls'
View
@@ -0,0 +1,12 @@
+require File.join(File.dirname(__FILE__), 'helper')
+
+class MappableTest < Test::Unit::TestCase #:nodoc: all
+
+ def test_math_error_classes
+ error_case = 0.49 * 180
+ from = Geokit::LatLng.new(error_case, error_case)
+ to = Geokit::LatLng.new(error_case, error_case)
+ assert_equal 0.0, Geokit::LatLng.distance_between_sphere(from, to, :kms)
+ end
+
+end

0 comments on commit 9c63ba8

Please sign in to comment.