Skip to content

Commit

Permalink
normalize whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
imajes committed Jan 14, 2012
1 parent a4e0c3d commit cd14aa6
Show file tree
Hide file tree
Showing 17 changed files with 485 additions and 485 deletions.
296 changes: 148 additions & 148 deletions lib/geokit/geocoders.rb

Large diffs are not rendered by default.

174 changes: 87 additions & 87 deletions lib/geokit/mappable.rb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions test/test_base_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
def self.do_get(url)
sleep(2)
end
end
end

# Defines common test fixtures.
def setup
@address = 'San Francisco, CA'
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
@address = 'San Francisco, CA'
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'

@latlng = Geokit::LatLng.new(37.7742, -122.417068)
@success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>@latlng.lat, :lng=>@latlng.lng})
@success.success = true
end
@success.success = true
end

def test_timeout_call_web_service
url = "http://www.anything.com"
Geokit::Geocoders::request_timeout = 1
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
end

def test_successful_call_web_service
url = "http://www.anything.com"
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
end

def test_find_geocoder_methods
public_methods = Geokit::Geocoders::Geocoder.public_methods.map { |m| m.to_s }
assert public_methods.include?("yahoo_geocoder")
Expand Down
44 changes: 22 additions & 22 deletions test/test_bounds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@
require 'lib/geokit'

class BoundsTest < Test::Unit::TestCase #:nodoc: all

def setup
# This is the area in Texas
@sw = Geokit::LatLng.new(32.91663,-96.982841)
@ne = Geokit::LatLng.new(32.96302,-96.919495)
@bounds=Geokit::Bounds.new(@sw,@ne)
@loc_a=Geokit::LatLng.new(32.918593,-96.958444) # inside bounds
@bounds=Geokit::Bounds.new(@sw,@ne)
@loc_a=Geokit::LatLng.new(32.918593,-96.958444) # inside bounds
@loc_b=Geokit::LatLng.new(32.914144,-96.958444) # outside bouds

# this is a cross-meridan area
@cross_meridian=Geokit::Bounds.normalize([30,170],[40,-170])
@inside_cm=Geokit::LatLng.new(35,175)
@inside_cm_2=Geokit::LatLng.new(35,-175)
@east_of_cm=Geokit::LatLng.new(35,-165)
@west_of_cm=Geokit::LatLng.new(35,165)

end
end

def test_equality
assert_equal Geokit::Bounds.new(@sw,@ne), Geokit::Bounds.new(@sw,@ne)
end
end

def test_normalize
res=Geokit::Bounds.normalize(@sw,@ne)
assert_equal res,Geokit::Bounds.new(@sw,@ne)
assert_equal res,Geokit::Bounds.new(@sw,@ne)
res=Geokit::Bounds.normalize([@sw,@ne])
assert_equal res,Geokit::Bounds.new(@sw,@ne)
res=Geokit::Bounds.normalize([@sw.lat,@sw.lng],[@ne.lat,@ne.lng])
assert_equal res,Geokit::Bounds.new(@sw,@ne)
res=Geokit::Bounds.normalize([[@sw.lat,@sw.lng],[@ne.lat,@ne.lng]])
assert_equal res,Geokit::Bounds.new(@sw,@ne)
end

def test_point_inside_bounds
assert @bounds.contains?(@loc_a)
end

def test_point_outside_bounds
assert !@bounds.contains?(@loc_b)
end
assert !@bounds.contains?(@loc_b)
end

def test_point_inside_bounds_cross_meridian
assert @cross_meridian.contains?(@inside_cm)
Expand All @@ -51,8 +51,8 @@ def test_point_inside_bounds_cross_meridian
def test_point_outside_bounds_cross_meridian
assert !@cross_meridian.contains?(@east_of_cm)
assert !@cross_meridian.contains?(@west_of_cm)
end
end

def test_center
assert_in_delta 32.939828,@bounds.center.lat,0.00005
assert_in_delta(-96.9511763,@bounds.center.lng,0.00005)
Expand All @@ -61,37 +61,37 @@ def test_center
def test_center_cross_meridian
assert_in_delta 35.41160, @cross_meridian.center.lat,0.00005
assert_in_delta 179.38112, @cross_meridian.center.lng,0.00005
end
end

def test_creation_from_circle
bounds=Geokit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
inside=Geokit::LatLng.new 32.9695270000,-96.9901590000
outside=Geokit::LatLng.new 32.8951550000,-96.9584440000
assert bounds.contains?(inside)
assert !bounds.contains?(outside)
end

def test_bounds_to_span
sw = Geokit::LatLng.new(32, -96)
ne = Geokit::LatLng.new(40, -70)
bounds = Geokit::Bounds.new(sw, ne)

assert_equal Geokit::LatLng.new(8, 26), bounds.to_span
end

def test_bounds_to_span_with_bounds_crossing_prime_meridian
sw = Geokit::LatLng.new(20, -70)
ne = Geokit::LatLng.new(40, 100)
bounds = Geokit::Bounds.new(sw, ne)

assert_equal Geokit::LatLng.new(20, 170), bounds.to_span
end

def test_bounds_to_span_with_bounds_crossing_dateline
sw = Geokit::LatLng.new(20, 100)
ne = Geokit::LatLng.new(40, -70)
bounds = Geokit::Bounds.new(sw, ne)

assert_equal Geokit::LatLng.new(20, 190), bounds.to_span
end
end
end
34 changes: 17 additions & 17 deletions test/test_ca_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
Geokit::Geocoders::geocoder_ca = "SOMEKEYVALUE"

class CaGeocoderTest < BaseGeocoderTest #:nodoc: all

CA_SUCCESS=<<-EOF
<?xml version="1.0" encoding="UTF-8" ?>
<geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
<geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
EOF

def setup
@ca_full_hash = {:street_address=>"2105 West 32nd Avenue",:city=>"Vancouver", :state=>"BC"}
@ca_full_loc = Geokit::GeoLoc.new(@ca_full_hash)
end
end

def test_geocoder_with_geo_loc_with_account
response = MockSuccess.new
response.expects(:body).returns(CA_SUCCESS)
url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
end

def test_service_unavailable
response = MockFailure.new
#Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
#Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
end
assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
end

private

def verify(location)
assert_equal "BC", location.state
assert_equal "Vancouver", location.city
assert_equal "49.243086,-123.153684", location.ll
assert !location.is_us?
assert_equal "Vancouver", location.city
assert_equal "49.243086,-123.153684", location.ll
assert !location.is_us?
end
end
end
30 changes: 15 additions & 15 deletions test/test_geoloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
require 'lib/geokit'

class GeoLocTest < Test::Unit::TestCase #:nodoc: all

def setup
@loc = Geokit::GeoLoc.new
end

def test_is_us
assert !@loc.is_us?
@loc.country_code = 'US'
assert @loc.is_us?
end

def test_success
assert !@loc.success?
@loc.success = false
assert !@loc.success?
@loc.success = true
assert @loc.success?
end

def test_street_number
@loc.street_address = '123 Spear St.'
assert_equal '123', @loc.street_number
end

def test_street_name
@loc.street_address = '123 Spear St.'
assert_equal 'Spear St.', @loc.street_name
end

def test_city
@loc.city = "san francisco"
assert_equal 'San Francisco', @loc.city
end

def test_full_address
@loc.city = 'San Francisco'
@loc.state = 'CA'
Expand All @@ -45,28 +45,28 @@ def test_full_address
@loc.full_address = 'Irving, TX, 75063, US'
assert_equal 'Irving, TX, 75063, US', @loc.full_address
end

def test_hash
@loc.city = 'San Francisco'
@loc.state = 'CA'
@loc.zip = '94105'
@loc.country_code = 'US'
@another = Geokit::GeoLoc.new @loc.to_hash
@another = Geokit::GeoLoc.new @loc.to_hash
assert_equal @loc, @another
end

def test_all
assert_equal [@loc], @loc.all
end

def test_to_yaml
@loc.city = 'San Francisco'
@loc.state = 'CA'
@loc.zip = '94105'
@loc.country_code = 'US'
assert_equal(
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nstreet_name: \nstreet_number: \nsuccess: false\nzip: \"94105\"\n",
assert_equal(
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nstreet_name: \nstreet_number: \nsuccess: false\nzip: \"94105\"\n",
@loc.to_yaml)
end
end

end
10 changes: 5 additions & 5 deletions test/test_geoplugin_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require File.join(File.dirname(__FILE__), 'test_base_geocoder')

class IpGeocoderTest < BaseGeocoderTest #:nodoc: all

IP_SUCCESS=<<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<geoPlugin>
Expand All @@ -24,8 +24,8 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
def setup
super
@success.provider = "geoPlugin"
end
end

def test_successful_lookup
success = MockSuccess.new
success.expects(:body).returns(IP_SUCCESS)
Expand All @@ -47,13 +47,13 @@ def test_invalid_ip
assert_not_nil location
assert !location.success?
end

def test_service_unavailable
failure = MockFailure.new
url = 'http://www.geoplugin.net/xml.gp?ip=10.10.10.10'
GeoKit::Geocoders::GeoPluginGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
location = GeoKit::Geocoders::GeoPluginGeocoder.geocode("10.10.10.10")
assert_not_nil location
assert !location.success?
end
end
end
Loading

0 comments on commit cd14aa6

Please sign in to comment.