test via points

This commit is contained in:
Emil Tin 2013-05-05 11:14:09 +02:00
parent 3afcd31f61
commit 67addfdb37
4 changed files with 89 additions and 19 deletions

View File

@ -12,9 +12,13 @@ Then /^routability should be$/ do |table|
['forw','backw','bothw'].each do |direction|
if table.headers.include? direction
if direction == 'forw' || direction == 'bothw'
response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}")
a = Location.new ORIGIN[0]+(1+WAY_SPACING*i)*@zoom, ORIGIN[1]
b = Location.new ORIGIN[0]+(3+WAY_SPACING*i)*@zoom, ORIGIN[1]
response = request_route [a,b]
elsif direction == 'backw' || direction == 'bothw'
response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}")
a = Location.new ORIGIN[0]+(3+WAY_SPACING*i)*@zoom, ORIGIN[1]
b = Location.new ORIGIN[0]+(1+WAY_SPACING*i)*@zoom, ORIGIN[1]
response = request_route [a,b]
end
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
got[direction] = route_status response

View File

@ -3,13 +3,28 @@ When /^I route I should get$/ do |table|
actual = []
OSRMLauncher.new do
table.hashes.each_with_index do |row,ri|
from_node = find_node_by_name row['from']
raise "*** unknown from-node '#{row['from']}" unless from_node
to_node = find_node_by_name row['to']
raise "*** unknown to-node '#{row['to']}" unless to_node
got = {'from' => row['from'], 'to' => row['to'] }
waypoints = []
if row['from'] and row['to']
node = find_node_by_name(row['from'])
raise "*** unknown from-node '#{row['from']}" unless node
waypoints << node
node = find_node_by_name(row['to'])
raise "*** unknown to-node '#{row['to']}" unless node
waypoints << node
got = {'from' => row['from'], 'to' => row['to'] }
elsif row['waypoints']
row['waypoints'].split(',').each do |n|
node = find_node_by_name(n.strip)
raise "*** unknown waypoint node '#{n.strip}" unless node
waypoints << node
end
got = {'waypoints' => row['waypoints'] }
else
raise "*** no waypoints"
end
params = {}
row.each_pair do |k,v|
if k =~ /param:(.*)/
@ -22,7 +37,7 @@ When /^I route I should get$/ do |table|
end
end
response = request_route("#{from_node.lat},#{from_node.lon}", "#{to_node.lat},#{to_node.lon}", params)
response = request_route(waypoints, params)
if response.code == "200" && response.body.empty? == false
json = JSON.parse response.body
if json['status'] == 0

View File

@ -8,16 +8,15 @@ class Hash
def to_param(namespace = nil)
collect do |key, value|
"#{key}=#{value}"
end.sort * '&'
end.sort
end
end
def request_path path, params={}
if params.any?
uri = URI.parse ["#{HOST}/#{path}",params.to_param].join('&')
else
uri = URI.parse "#{HOST}/#{path}"
end
def request_path path, waypoints=[], options={}
locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" }
params = (locs + options.to_param).join('&')
params = nil if params==""
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
Timeout.timeout(REQUEST_TIMEOUT) do
Net::HTTP.get_response uri
end
@ -27,9 +26,9 @@ rescue Timeout::Error
raise "*** osrm-routed did not respond."
end
def request_route a,b, params={}
def request_route waypoints, params={}
defaults = { 'output' => 'json', 'instructions' => true, 'alt' => true }
request_path "viaroute?loc=#{a}&loc=#{b}", defaults.merge(params)
request_path "viaroute", waypoints, defaults.merge(params)
end
def parse_response response

View File

@ -0,0 +1,52 @@
@routing @testbot @via
Feature: Via points
Background:
Given the profile "testbot"
Scenario: Simple via point
Given the node map
| a | b | c |
And the ways
| nodes |
| abc |
When I route I should get
| waypoints | route |
| a,b,c | abc |
| c,b,a | abc |
Scenario: Via point at a dead end
Given the node map
| a | b | c |
| | d | |
And the ways
| nodes |
| abc |
| bd |
When I route I should get
| waypoints | route |
| a,d,c | abc,bd,bd,abc |
| c,d,a | abc,bd,bd,abc |
Scenario: Multiple via points
Given the node map
| a | | c | | e | |
| | b | | d | | f |
And the ways
| nodes |
| ace |
| bdf |
| ab |
| bc |
| cd |
| de |
| ef |
When I route I should get
| waypoints | route |
| a,b,c,d,e,f | ab,bc,cd,de,ef |