]> projects.mako.cc - selectricity/blob - vendor/plugins/geokit/test/bounds_test.rb
Embeddable elctions now scale based on how many candidates in the election there...
[selectricity] / vendor / plugins / geokit / test / bounds_test.rb
1 $LOAD_PATH.unshift File.join('..', 'lib')
2 require 'geo_kit/mappable'
3 require 'test/unit'
4
5 class BoundsTest < Test::Unit::TestCase #:nodoc: all
6   
7   def setup
8     # This is the area in Texas
9     @sw = GeoKit::LatLng.new(32.91663,-96.982841)
10     @ne = GeoKit::LatLng.new(32.96302,-96.919495)
11     @bounds=GeoKit::Bounds.new(@sw,@ne) 
12     @loc_a=GeoKit::LatLng.new(32.918593,-96.958444) # inside bounds    
13     @loc_b=GeoKit::LatLng.new(32.914144,-96.958444) # outside bouds
14     
15     # this is a cross-meridan area
16     @cross_meridian=GeoKit::Bounds.normalize([30,170],[40,-170])
17     @inside_cm=GeoKit::LatLng.new(35,175)
18     @inside_cm_2=GeoKit::LatLng.new(35,-175)
19     @east_of_cm=GeoKit::LatLng.new(35,-165)
20     @west_of_cm=GeoKit::LatLng.new(35,165)
21
22   end  
23
24   def test_equality
25     assert_equal GeoKit::Bounds.new(@sw,@ne), GeoKit::Bounds.new(@sw,@ne)
26   end  
27   
28   def test_normalize
29     res=GeoKit::Bounds.normalize(@sw,@ne)
30     assert_equal res,GeoKit::Bounds.new(@sw,@ne)     
31     res=GeoKit::Bounds.normalize([@sw,@ne])
32     assert_equal res,GeoKit::Bounds.new(@sw,@ne)
33     res=GeoKit::Bounds.normalize([@sw.lat,@sw.lng],[@ne.lat,@ne.lng])
34     assert_equal res,GeoKit::Bounds.new(@sw,@ne)
35     res=GeoKit::Bounds.normalize([[@sw.lat,@sw.lng],[@ne.lat,@ne.lng]])
36     assert_equal res,GeoKit::Bounds.new(@sw,@ne)
37   end
38   
39   def test_point_inside_bounds
40     assert @bounds.contains?(@loc_a)
41   end
42
43   def test_point_outside_bounds
44     assert !@bounds.contains?(@loc_b) 
45   end  
46
47   def test_point_inside_bounds_cross_meridian
48     assert @cross_meridian.contains?(@inside_cm)
49     assert @cross_meridian.contains?(@inside_cm_2)
50   end
51
52   def test_point_outside_bounds_cross_meridian
53     assert !@cross_meridian.contains?(@east_of_cm)
54     assert !@cross_meridian.contains?(@west_of_cm)
55   end    
56   
57   def test_center
58     assert_in_delta 32.939828,@bounds.center.lat,0.00005
59     assert_in_delta -96.9511763,@bounds.center.lng,0.00005
60   end
61
62   def test_center_cross_meridian
63     assert_in_delta 35.41160, @cross_meridian.center.lat,0.00005
64     assert_in_delta 179.38112, @cross_meridian.center.lng,0.00005
65   end  
66   
67   def test_creation_from_circle
68     bounds=GeoKit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
69     inside=GeoKit::LatLng.new 32.9695270000,-96.9901590000
70     outside=GeoKit::LatLng.new 32.8951550000,-96.9584440000
71     assert bounds.contains?(inside)
72     assert !bounds.contains?(outside)
73   end
74   
75 end

Benjamin Mako Hill || Want to submit a patch?