working on cucumber tests

This commit is contained in:
Emil Tin 2012-01-31 19:01:54 +01:00
parent a60ed5c78a
commit 18542d1df1
9 changed files with 160 additions and 75 deletions

View File

@ -1,7 +1,7 @@
@routing @basic
Feature: Basic Routing
Scenario: Smallest possible datasat
Scenario Outline: Smallest possible datasat
Given the nodes
| a | b |
@ -9,12 +9,31 @@ Feature: Basic Routing
| nodes |
| ab |
When I route I should get
When I route between "<from>" and "<to>"
Then "<route>" should be returned
Examples:
| from | to | route |
| a | b | ab |
| b | a | ba |
Scenario: Connected ways
Scenario Outline: Smallest possible datasat
Given the nodes
| a | b |
And the ways
| nodes |
| ab |
When I route between "<from>" and "<to>"
Then "<route>" should be returned
Examples:
| from | to | route |
| a | b | ab |
| b | a | ba |
Scenario Outline: Connected ways
Given the nodes
| a | | c |
| | b | |
@ -24,7 +43,10 @@ Feature: Basic Routing
| ab |
| bc |
When I route I should get
When I route between "<from>" and "<to>"
Then "<route>" should be returned
Examples:
| from | to | route |
| a | c | abc |
| c | a | cba |
@ -33,7 +55,7 @@ Feature: Basic Routing
| b | c | bc |
| c | b | cb |
Scenario: Unconnected ways
Scenario Outline: Unconnected ways
Given the nodes
| a | b |
| c | d |
@ -43,7 +65,10 @@ Feature: Basic Routing
| ab |
| cd |
When I route I should get
When I route between "<from>" and "<to>"
Then "<route>" should be returned
Examples:
| from | to | route |
| a | b | ab |
| b | a | ba |
@ -56,7 +81,7 @@ 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 |
@ -66,8 +91,10 @@ Feature: Basic Routing
| apb | primary |
| asb | secondary |
When I route I should get
When I route between "<from>" and "<to>"
Then "<route>" should be returned
Examples:
| from | to | route |
| a | b | apb |
| b | a | bpa |

View File

@ -3,6 +3,7 @@ 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,9 +38,8 @@ Feature: Oneway streets
| primary | -1 | | x |
Scenario: Disabling oneways in speedprofile
Given the speedprofile
Given the speedprofile settings
| obeyOneways | no |
Then routability should be
| highway | junction | oneway | forw | backw |
| primary | | yes | 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,7 +77,7 @@ 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

View File

@ -12,7 +12,7 @@ Feature: Outlines
| ab |
| bc |
When I route I between "<from>" and "<to>"
When I route from "<from>" to "<to>"
Then I should get the route "<route>"
Examples:

View File

@ -1,8 +1,8 @@
@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 | |
@ -17,7 +17,10 @@ Feature: Turn restrictions
| from | to | via | restriction |
| sj | ja | j | no_left_turn |
When I route I should get
When I route between "<from>" and "<to>"
Then "<route>" should be returned
Examples:
| from | to | route |
| a | b | ajb |
| a | s | ajs |
@ -25,4 +28,3 @@ Feature: Turn restrictions
| b | s | bjs |
| s | a | |
| s | b | sjb |

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
Before do
reset_data
end

View File

@ -1,9 +1,20 @@
[bicycle]
primary = 15
obeyOneways = yes
useRestrictions = yes
accessTag = bicycle
excludeFromGrid = ferry
defaultSpeed = 15
obeyBollards = no
trafficLightPenalty = 10
[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