test via points
This commit is contained in:
parent
3afcd31f61
commit
67addfdb37
@ -12,9 +12,13 @@ Then /^routability should be$/ do |table|
|
|||||||
['forw','backw','bothw'].each do |direction|
|
['forw','backw','bothw'].each do |direction|
|
||||||
if table.headers.include? direction
|
if table.headers.include? direction
|
||||||
if direction == 'forw' || direction == 'bothw'
|
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'
|
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
|
end
|
||||||
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
|
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
|
||||||
got[direction] = route_status response
|
got[direction] = route_status response
|
||||||
|
@ -3,13 +3,28 @@ When /^I route I should get$/ do |table|
|
|||||||
actual = []
|
actual = []
|
||||||
OSRMLauncher.new do
|
OSRMLauncher.new do
|
||||||
table.hashes.each_with_index do |row,ri|
|
table.hashes.each_with_index do |row,ri|
|
||||||
from_node = find_node_by_name row['from']
|
waypoints = []
|
||||||
raise "*** unknown from-node '#{row['from']}" unless from_node
|
if row['from'] and row['to']
|
||||||
to_node = find_node_by_name row['to']
|
node = find_node_by_name(row['from'])
|
||||||
raise "*** unknown to-node '#{row['to']}" unless to_node
|
raise "*** unknown from-node '#{row['from']}" unless node
|
||||||
|
waypoints << node
|
||||||
got = {'from' => row['from'], 'to' => row['to'] }
|
|
||||||
|
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 = {}
|
params = {}
|
||||||
row.each_pair do |k,v|
|
row.each_pair do |k,v|
|
||||||
if k =~ /param:(.*)/
|
if k =~ /param:(.*)/
|
||||||
@ -22,7 +37,7 @@ When /^I route I should get$/ do |table|
|
|||||||
end
|
end
|
||||||
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
|
if response.code == "200" && response.body.empty? == false
|
||||||
json = JSON.parse response.body
|
json = JSON.parse response.body
|
||||||
if json['status'] == 0
|
if json['status'] == 0
|
||||||
|
@ -8,16 +8,15 @@ class Hash
|
|||||||
def to_param(namespace = nil)
|
def to_param(namespace = nil)
|
||||||
collect do |key, value|
|
collect do |key, value|
|
||||||
"#{key}=#{value}"
|
"#{key}=#{value}"
|
||||||
end.sort * '&'
|
end.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_path path, params={}
|
def request_path path, waypoints=[], options={}
|
||||||
if params.any?
|
locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" }
|
||||||
uri = URI.parse ["#{HOST}/#{path}",params.to_param].join('&')
|
params = (locs + options.to_param).join('&')
|
||||||
else
|
params = nil if params==""
|
||||||
uri = URI.parse "#{HOST}/#{path}"
|
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
|
||||||
end
|
|
||||||
Timeout.timeout(REQUEST_TIMEOUT) do
|
Timeout.timeout(REQUEST_TIMEOUT) do
|
||||||
Net::HTTP.get_response uri
|
Net::HTTP.get_response uri
|
||||||
end
|
end
|
||||||
@ -27,9 +26,9 @@ rescue Timeout::Error
|
|||||||
raise "*** osrm-routed did not respond."
|
raise "*** osrm-routed did not respond."
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_route a,b, params={}
|
def request_route waypoints, params={}
|
||||||
defaults = { 'output' => 'json', 'instructions' => true, 'alt' => true }
|
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
|
end
|
||||||
|
|
||||||
def parse_response response
|
def parse_response response
|
||||||
|
52
features/testbot/via.feature
Normal file
52
features/testbot/via.feature
Normal 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 |
|
Loading…
Reference in New Issue
Block a user