From 18542d1df12fa4050b1f29dc66cb5198db440f5c Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 31 Jan 2012 19:01:54 +0100 Subject: [PATCH] working on cucumber tests --- features/basic.feature | 65 +++++++++++++++++-------- features/oneways.feature | 18 +++---- features/outlines.feature | 2 +- features/restrictions.feature | 18 ++++--- features/step_definitions/processing.rb | 7 --- features/step_definitions/routing.rb | 61 +++++++++++++++++------ features/step_definitions/test_data.rb | 32 +++++++++--- features/support/hooks.rb | 3 ++ test/speedprofiles/default.ini | 29 +++++++---- 9 files changed, 160 insertions(+), 75 deletions(-) create mode 100644 features/support/hooks.rb diff --git a/features/basic.feature b/features/basic.feature index 860801130..07cdb2505 100644 --- a/features/basic.feature +++ b/features/basic.feature @@ -1,30 +1,52 @@ @routing @basic Feature: Basic Routing - Scenario: Smallest possible datasat - Given the nodes + Scenario Outline: Smallest possible datasat + Given the nodes | a | b | - + And the ways | nodes | | ab | - - When I route I should get + + When I route between "" and "" + Then "" should be returned + + Examples: + | from | to | route | + | a | b | ab | + | b | a | ba | + + Scenario Outline: Smallest possible datasat + Given the nodes + | a | b | + + And the ways + | nodes | + | ab | + + When I route between "" and "" + Then "" should be returned + + Examples: | from | to | route | | a | b | ab | | b | a | ba | - Scenario: Connected ways + Scenario Outline: Connected ways Given the nodes | a | | c | - | | b | | + | | b | | And the ways | nodes | | ab | | bc | - - When I route I should get + + When I route between "" and "" + Then "" should be returned + + Examples: | from | to | route | | a | c | abc | | c | a | cba | @@ -33,17 +55,20 @@ Feature: Basic Routing | b | c | bc | | c | b | cb | - Scenario: Unconnected ways + Scenario Outline: Unconnected ways Given the nodes | a | b | | c | d | - + And the ways | nodes | | ab | | cd | - - When I route I should get + + When I route between "" and "" + Then "" should be returned + + Examples: | from | to | route | | a | b | ab | | b | a | ba | @@ -56,18 +81,20 @@ Feature: Basic Routing | a | d | | | d | a | | - Scenario: Pick the fastest way type + Scenario Outline: Pick the fastest way type Given the nodes | a | s | | p | b | - + And the ways | nodes | highway | | apb | primary | | asb | secondary | - - When I route I should get + + When I route between "" and "" + Then "" should be returned + + Examples: | from | to | route | | a | b | apb | - | b | a | bpa | - + | b | a | bpa | \ No newline at end of file diff --git a/features/oneways.feature b/features/oneways.feature index ea4cd5b6e..f8a64ef2b 100644 --- a/features/oneways.feature +++ b/features/oneways.feature @@ -1,8 +1,9 @@ @routing @oneways Feature: Oneway streets Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing - + Scenario: Implied oneways + Given the speedprofile "car" Then routability should be | highway | junction | forw | backw | | motorway | | x | x | @@ -12,6 +13,7 @@ Feature: Oneway streets | primary | roundabout | x | | Scenario: Overriding implied oneways + Given the defaults Then routability should be | highway | junction | oneway | forw | backw | | motorway_link | | no | x | x | @@ -22,6 +24,7 @@ Feature: Oneway streets | primary | roundabout | -1 | | x | Scenario: Handle various oneway tag values + Given the defaults Then routability should be | highway | oneway | forw | backw | | primary | | x | x | @@ -35,10 +38,9 @@ Feature: Oneway streets | primary | -1 | | x | Scenario: Disabling oneways in speedprofile - Given the speedprofile + Given the speedprofile settings | obeyOneways | no | - - Then routability should be + Then routability should be | highway | junction | oneway | forw | backw | | primary | | yes | x | x | | primary | | true | x | x | @@ -49,9 +51,7 @@ Feature: Oneway streets | primary | roundabout | | x | x | Scenario: Oneways and bicycles - Given the speedprofile - | accessTag | bicycle | - + Given the defaults Then routability should be | highway | junction | oneway | oneway:bicycle | forw | backw | | primary | | | yes | x | | @@ -77,9 +77,9 @@ Feature: Oneway streets | primary | roundabout | | -1 | | x | Scenario: Cars should not be affected by bicycle tags - Given the speedprofile + Given the speedprofile settings | accessTag | motorcar | - + Then routability should be | highway | junction | oneway | oneway:bicycle | forw | backw | | primary | | yes | yes | x | | diff --git a/features/outlines.feature b/features/outlines.feature index 1255bd50b..48394f9f7 100644 --- a/features/outlines.feature +++ b/features/outlines.feature @@ -12,7 +12,7 @@ Feature: Outlines | ab | | bc | - When I route I between "" and "" + When I route from "" to "" Then I should get the route "" Examples: diff --git a/features/restrictions.feature b/features/restrictions.feature index 4ecef9654..dd35b1126 100644 --- a/features/restrictions.feature +++ b/features/restrictions.feature @@ -1,28 +1,30 @@ @routing @restrictions Feature: Turn restrictions - OSRM should handle turn restrictions as defined by http://wiki.openstreetmap.org/wiki/Relation:restriction + Handle turn restrictions as defined by http://wiki.openstreetmap.org/wiki/Relation:restriction - Scenario: No left turn at T-junction + Scenario Outline: No left turn at T-junction Given the nodes | a | j | b | | | s | | - + And the ways | nodes | | aj | | jb | | sj | - + And the relations | from | to | via | restriction | | sj | ja | j | no_left_turn | - - When I route I should get + + When I route between "" and "" + Then "" should be returned + + Examples: | from | to | route | | a | b | ajb | | a | s | ajs | | b | a | bja | | b | s | bjs | | s | a | | - | s | b | sjb | - + | s | b | sjb | \ No newline at end of file diff --git a/features/step_definitions/processing.rb b/features/step_definitions/processing.rb index d2f40f3dd..86c6f63d9 100644 --- a/features/step_definitions/processing.rb +++ b/features/step_definitions/processing.rb @@ -75,10 +75,3 @@ end When /^preprocessed files for "([^"]*)" has been removed$/ do |file| FileUtils.rm_r Dir["#{file}.*"], :secure => true end - - -Given /^the speed profile$/ do |table| - table.hashes.each do |hash| - #Whatever you need to do - end -end \ No newline at end of file diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index ab349367f..9b49b2a80 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -1,4 +1,5 @@ + def request_route a,b uri = URI.parse "http://localhost:5000/viaroute&start=#{a}&dest=#{b}&output=json&geomformat=cmp" #puts "routing: #{uri}" @@ -65,7 +66,7 @@ end Then /^I should get a route$/ do step "I should get a valid response" step "a route should be found" - puts @response.body + #puts @response.body end Then /^I should not get a route$/ do @@ -145,7 +146,7 @@ end def parse_response response if response.code == "200" && response.body.empty? == false json = JSON.parse response.body - puts response.body + #puts response.body if json['status'] == 0 route = json['route_instructions'].map { |r| r[1] }.reject(&:empty?).join(', ') if route.empty? @@ -184,20 +185,50 @@ When /^I route on tagged ways I should get $/ do |table| pending end +When /^I route between "([^"]*)" and "([^"]*)"$/ do |from,to| +end -When /^I speak I should get$/ do |table| - actual = [['one','two','three']] - table.hashes.each do |row| - actual << [ row['one'].dup, row['two'].dup, 'xx' ] +Then /^"([^"]*)" should be returned$/ do |route| +end + +def build_ways_from_table table + #add one unconnected way for each row + table.hashes.each_with_index do |row,ri| + #two nodes... + node1 = OSM::Node.new nil, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+0*ZOOM, ORIGIN[1]-ri*ZOOM + node2 = OSM::Node.new nil, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+1*ZOOM, ORIGIN[1]-ri*ZOOM + node1.uid = OSM_UID + node2.uid = OSM_UID + osm_db << node1 + osm_db << node2 + + #...with a way between them + way = OSM::Way.new -ri-1, OSM_USER, OSM_TIMESTAMP + way.uid = OSM_UID + tags = row.dup + tags.delete 'forw' + tags.delete 'backw' + tags.reject! { |k,v| v=='' } + way << tags + way << node1 + way << node2 + osm_db << way + end + Dir.chdir TEST_FOLDER do + write_osm + end + must_reprocess +end + +Then /^routability should be$/ do |table| + build_ways_from_table table + reprocess_if_needed + actual = [ table.column_names ] + Dir.chdir 'test' do + launch + p "#{ORIGIN[0]+0*ZOOM},#{ORIGIN[1]-0*ZOOM}", "#{ORIGIN[0]+1*ZOOM},#{ORIGIN[1]-0*ZOOM}" + p request_route("#{ORIGIN[0]+0*ZOOM},#{ORIGIN[1]-0*ZOOM}", "#{ORIGIN[0]+1*ZOOM},#{ORIGIN[1]-0*ZOOM}").body + kill end table.diff! actual end - -When /^I route I between "([^"]*)" and "([^"]*)"$/ do |from, to| -end - -Then /^I should get the route "([^"]*)"$/ do |route| - route.should == "xx" -end - - \ No newline at end of file diff --git a/features/step_definitions/test_data.rb b/features/step_definitions/test_data.rb index b947e8401..ca32387e5 100644 --- a/features/step_definitions/test_data.rb +++ b/features/step_definitions/test_data.rb @@ -11,6 +11,8 @@ DATA_FOLDER = 'data' OSM_FILE = 'test' LOG_FILE = 'test.log' +DEFAULT_SPEEDPROFILE = 'bicycle' + ORIGIN = [1,1] ZOOM = 0.001 @@ -51,16 +53,15 @@ def find_way_by_name s end def reset_data + Dir.chdir "#{TEST_FOLDER}" do + clear_log + clear_data_files + end osm_db.clear name_node_hash.clear name_way_hash.clear must_reprocess reset_speedprofile - $stdout.flush - Dir.chdir "#{TEST_FOLDER}" do - clear_log - clear_data_files - end end def clear_data_files @@ -77,7 +78,12 @@ end def reset_speedprofile @speedprofile = {} - s = File.read 'test/speedprofiles/default.ini' + read_speedprofile DEFAULT_SPEEDPROFILE +end + +def read_speedprofile profile + @speedprofile = {} + s = File.read "test/speedprofiles/#{profile}.ini" s.scan /(.*)=(.*)/ do |option| @speedprofile[option[0].strip] = option[1].strip end @@ -121,8 +127,18 @@ def write_osm end +Given /^the speedprofile "([^"]*)"$/ do |profile| + read_speedprofile profile +end + + +Given /^the speedprofile settings$/ do |table| + table.raw.each do |row| + speedprofile[ row[0] ] = row[1] + end +end + Given /^the nodes$/ do |table| - reset_data table.raw.each_with_index do |row,ri| row.each_with_index do |name,ci| unless name.empty? @@ -163,3 +179,5 @@ Given /^the relations$/ do |table| end end +Given /^the defaults$/ do +end diff --git a/features/support/hooks.rb b/features/support/hooks.rb new file mode 100644 index 000000000..adf806b64 --- /dev/null +++ b/features/support/hooks.rb @@ -0,0 +1,3 @@ +Before do + reset_data +end \ No newline at end of file diff --git a/test/speedprofiles/default.ini b/test/speedprofiles/default.ini index aa8befd33..a7db8683f 100644 --- a/test/speedprofiles/default.ini +++ b/test/speedprofiles/default.ini @@ -1,9 +1,20 @@ -[bicycle] - primary = 15 - obeyOneways = yes - useRestrictions = yes - accessTag = bicycle - excludeFromGrid = ferry - defaultSpeed = 15 - obeyBollards = no - trafficLightPenalty = 10 \ No newline at end of file +[default] + accessTag = motorcar + defaultSpeed = 50 + + barrier = bollard + + motorway = 110 + motorway_link = 90 + trunk = 90 + trunk_link = 70 + primary = 70 + primary_link = 60 + secondary = 60 + secondary_link = 50 + tertiary = 40 + residential = 30 + living_street = 25 + service = 25 + unclassified = 25 + \ No newline at end of file