From 67addfdb373700b34da0945af0e4d5f8ada01d7d Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sun, 5 May 2013 11:14:09 +0200 Subject: [PATCH] test via points --- features/step_definitions/routability.rb | 8 +++- features/step_definitions/routing.rb | 31 ++++++++++---- features/support/route.rb | 17 ++++---- features/testbot/via.feature | 52 ++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 features/testbot/via.feature diff --git a/features/step_definitions/routability.rb b/features/step_definitions/routability.rb index 0af027a98..565c7445b 100644 --- a/features/step_definitions/routability.rb +++ b/features/step_definitions/routability.rb @@ -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 diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 4c4584379..13c8b6a04 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -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 diff --git a/features/support/route.rb b/features/support/route.rb index 0d67bc076..86ea263fd 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -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 diff --git a/features/testbot/via.feature b/features/testbot/via.feature new file mode 100644 index 000000000..0ec365daf --- /dev/null +++ b/features/testbot/via.feature @@ -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 |