]> git.openstreetmap.org Git - rails.git/commitdiff
node unit tests with inside limits now.
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Tue, 8 Jul 2008 15:38:31 +0000 (15:38 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Tue, 8 Jul 2008 15:38:31 +0000 (15:38 +0000)
test/fixtures/current_nodes.yml
test/unit/node_test.rb

index 7af9bbda10a3387b31608e12a29a4143482531c1..ef5e688f6a1a79a35aaf738d059dbd461982bbac 100644 (file)
@@ -42,36 +42,64 @@ node_used_by_relationship:
   
 node_too_far_north:
   id: 6
   
 node_too_far_north:
   id: 6
-  latitude: <%= 91*SCALE %>
+  latitude: <%= 90.01*SCALE %>
   longitude: <%= 6*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
   longitude: <%= 6*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
+node_north_limit:
+  id: 11
+  latitude: <%= 90*SCALE %>
+  longitude: <%= 11*SCALE %>
+  user_id: 1
+  timestamp: 2008-07-08 14:50:00
+  
 node_too_far_south:
   id: 7
 node_too_far_south:
   id: 7
-  latitude: <%= -91*SCALE %>
+  latitude: <%= -90.01*SCALE %>
   longitude: <%= 7*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
   longitude: <%= 7*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
+node_south_limit:
+  id: 12
+  latitude: <%= -90*SCALE %>
+  longitude: <%= 12*SCALE %>
+  user_id: 1
+  timestamp: 2008-07-08 15:02:18
+  
 node_too_far_west:
   id: 8
   latitude: <%= 8*SCALE %>
 node_too_far_west:
   id: 8
   latitude: <%= 8*SCALE %>
-  longitude: <%= -181*SCALE %>
+  longitude: <%= -180.01*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
+node_west_limit:
+  id: 13
+  latitude: <%= 13*SCALE %>
+  longitude: <%= -180*SCALE %>
+  user_id: 1
+  timestamp: 2008-07-08 15:17:37
+  
 node_too_far_east:
   id: 9
   latitude: <%= 9*SCALE %>
 node_too_far_east:
   id: 9
   latitude: <%= 9*SCALE %>
-  longitude: <%= 181*SCALE %>
+  longitude: <%= 180.01*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
+node_east_limit:
+  id: 14
+  latitude: <%= 14*SCALE %>
+  longitude: <%= 180*SCALE %>
+  user_id: 1
+  timestamp: 2008-07-08 15:46:16
+  
 node_totally_wrong:
   id: 10
 node_totally_wrong:
   id: 10
-  latitude: <%= 1000*SCALE %>
-  longitude: <%= 1000*SCALE %>
+  latitude: <%= 200*SCALE %>
+  longitude: <%= 200*SCALE %>
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
   user_id: 1
   timestamp: 2007-01-01 00:00:00
   
index 460c13a025318252748422aee76540671878798b..87b61a7453a541263d7c0ca2c263a60651326f96 100644 (file)
@@ -8,40 +8,64 @@ class NodeTest < Test::Unit::TestCase
   set_fixture_class :currenr_node_tags => :NodeTag
     
   def test_node_too_far_north
   set_fixture_class :currenr_node_tags => :NodeTag
     
   def test_node_too_far_north
-         node = current_nodes(:node_too_far_north)
-    assert_equal node.lat, current_nodes(:node_too_far_north).latitude/SCALE
-    assert_equal node.lon, current_nodes(:node_too_far_north).longitude/SCALE
-    assert_equal false, node.valid?
+         invalid_node_test(:node_too_far_north)
+  end
+  
+  def test_node_north_limit
+    valid_node_test(:node_north_limit)
   end
   
   def test_node_too_far_south
   end
   
   def test_node_too_far_south
-    node = current_nodes(:node_too_far_south)
-    assert_equal node.lat, current_nodes(:node_too_far_south).latitude/SCALE
-    assert_equal node.lon, current_nodes(:node_too_far_south).longitude/SCALE
-    assert_equal false, node.valid?
+    invalid_node_test(:node_too_far_south)
+  end
+  
+  def test_node_south_limit
+    valid_node_test(:node_south_limit)
   end
   
   def test_node_too_far_west
   end
   
   def test_node_too_far_west
-    node = current_nodes(:node_too_far_west)
-    assert_equal node.lat, current_nodes(:node_too_far_west).latitude/SCALE
-    assert_equal node.lon, current_nodes(:node_too_far_west).longitude/SCALE
-    assert_equal false, node.valid?
+    invalid_node_test(:node_too_far_west)
+  end
+  
+  def test_node_west_limit
+    valid_node_test(:node_west_limit)
   end
   
   def test_node_too_far_east
   end
   
   def test_node_too_far_east
-    node = current_nodes(:node_too_far_east)
-    assert_equal node.lat, current_nodes(:node_too_far_east).latitude/SCALE
-    assert_equal node.lon, current_nodes(:node_too_far_east).longitude/SCALE
-    assert_equal false, node.valid?
+    invalid_node_test(:node_too_far_east)
+  end
+  
+  def test_node_east_limit
+    valid_node_test(:node_east_limit)
   end
   
   def test_totally_wrong
   end
   
   def test_totally_wrong
-    node = current_nodes(:node_totally_wrong)
-    #assert_equal node.lat, current_nodes(:node_totally_wrong).latitude/SCALE
-    #assert_equal node.lon, current_nodes(:node_totally_wrong).longitude/SCALE
+    invalid_node_test(:node_totally_wrong)
+  end
+  
+  # This helper method will check to make sure that a node is within the world, and
+  # has the the same lat, lon and timestamp than what was put into the db by 
+  # the fixture
+  def valid_node_test(nod)
+    node = current_nodes(nod)
+    assert_equal node.lat, current_nodes(nod).latitude.to_f/SCALE
+    assert_equal node.lon, current_nodes(nod).longitude.to_f/SCALE
+    assert_equal node.timestamp, current_nodes(nod).timestamp
+    assert_valid node
+  end
+  
+  # This helpermethod will check to make sure that a node is outwith the world, 
+  # and has the same lat, lon and timesamp than what was put into the db by the
+  # fixture
+  def invalid_node_test(nod)
+    node = current_nodes(nod)
+    assert_equal node.lat, current_nodes(nod).latitude.to_f/SCALE
+    assert_equal node.lon, current_nodes(nod).longitude.to_f/SCALE
+    assert_equal node.timestamp, current_nodes(nod).timestamp
     assert_equal false, node.valid?
   end
   
     assert_equal false, node.valid?
   end
   
+  # Check that you can create a node and store it
   def test_create
     node_template = Node.new(:latitude => 12.3456,
                              :longitude => 65.4321,
   def test_create
     node_template = Node.new(:latitude => 12.3456,
                              :longitude => 65.4321,