From: Shaun McDonald Date: Tue, 8 Jul 2008 15:38:31 +0000 (+0000) Subject: node unit tests with inside limits now. X-Git-Tag: live~7601^2~321 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/dce4f18a3e0d952e482a911d41971893fb2d858d node unit tests with inside limits now. --- diff --git a/test/fixtures/current_nodes.yml b/test/fixtures/current_nodes.yml index 7af9bbda1..ef5e688f6 100644 --- a/test/fixtures/current_nodes.yml +++ b/test/fixtures/current_nodes.yml @@ -42,36 +42,64 @@ node_used_by_relationship: 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 +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 - latitude: <%= -91*SCALE %> + latitude: <%= -90.01*SCALE %> 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 %> - longitude: <%= -181*SCALE %> + longitude: <%= -180.01*SCALE %> 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 %> - longitude: <%= 181*SCALE %> + longitude: <%= 180.01*SCALE %> 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 - latitude: <%= 1000*SCALE %> - longitude: <%= 1000*SCALE %> + latitude: <%= 200*SCALE %> + longitude: <%= 200*SCALE %> user_id: 1 timestamp: 2007-01-01 00:00:00 diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 460c13a02..87b61a745 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -8,40 +8,64 @@ class NodeTest < Test::Unit::TestCase 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 - 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 - 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 - 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 - 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 + # Check that you can create a node and store it def test_create node_template = Node.new(:latitude => 12.3456, :longitude => 65.4321,