diff --git a/features/step_definitions/matching.rb b/features/step_definitions/matching.rb index e9b723460..607efedd9 100644 --- a/features/step_definitions/matching.rb +++ b/features/step_definitions/matching.rb @@ -58,6 +58,9 @@ When /^I match I should get$/ do |table| end end + puts table + puts sub_matchings + ok = true encoded_result = "" extended_target = "" diff --git a/features/step_definitions/trip.rb b/features/step_definitions/trip.rb new file mode 100644 index 000000000..007717e04 --- /dev/null +++ b/features/step_definitions/trip.rb @@ -0,0 +1,121 @@ +When /^I plan a trip I should get$/ do |table| + reprocess + actual = [] + OSRMLoader.load(self,"#{prepared_file}.osrm") do + table.hashes.each_with_index do |row,ri| + if row['request'] + got = {'request' => row['request'] } + response = request_url row['request'] + else + params = @query_params + 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'] } + response = request_trip waypoints, params + 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'] } + response = request_trip waypoints, params + else + raise "*** no waypoints" + end + end + + row.each_pair do |k,v| + if k =~ /param:(.*)/ + if v=='(nil)' + params[$1]=nil + elsif v!=nil + params[$1]=v + end + got[k]=v + end + end + + if response.body.empty? == false + json = JSON.parse response.body + end + + if table.headers.include? 'status' + got['status'] = json['status'].to_s + end + if table.headers.include? 'message' + got['message'] = json['status_message'] + end + if table.headers.include? '#' # comment column + got['#'] = row['#'] # copy value so it always match + end + + if response.code == "200" + if table.headers.include? 'trips' + sub_trips = json['trips'].compact.map { |sub| sub['via_points']} + end + end + + ###################### + ok = true + encoded_result = "" + extended_target = "" + row['trips'].split(',').each_with_index do |sub, sub_idx| + if sub_idx >= sub_trips.length + ok = false + break + end + + ok = false; + #TODO: Check all rotations of the round trip + sub.length.times do |node_idx| + node = find_node_by_name(sub[node_idx]) + out_node = sub_trips[sub_idx][node_idx] + if FuzzyMatch.match_location out_node, node + encoded_result += sub[node_idx] + extended_target += sub[node_idx] + ok = true + else + encoded_result += "? [#{out_node[0]},#{out_node[1]}]" + extended_target += "#{sub[node_idx]} [#{node.lat},#{node.lon}]" + end + end + end + + if ok + got['trips'] = row['trips'] + got['via_points'] = row['via_points'] + else + got['trips'] = encoded_result + row['trips'] = extended_target + log_fail row,got, { 'trip' => {:query => @query, :response => response} } + end + + + ok = true + row.keys.each do |key| + if FuzzyMatch.match got[key], row[key] + got[key] = row[key] + else + ok = false + end + end + + unless ok + log_fail row,got, { 'trip' => {:query => @query, :response => response} } + end + + actual << got + end + end + table.diff! actual +end + diff --git a/features/support/trip.rb b/features/support/trip.rb new file mode 100644 index 000000000..6ea901094 --- /dev/null +++ b/features/support/trip.rb @@ -0,0 +1,14 @@ +require 'net/http' +HOST = "http://127.0.0.1:#{OSRM_PORT}" + +def request_trip waypoints=[], params={} + defaults = { 'output' => 'json' } + locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" } + + params = (locs + defaults.merge(params).to_param).join('&') + params = nil if params=="" + + uri = generate_request_url ("trip" + '?' + params) + response = send_request uri, waypoints, params +end + diff --git a/features/testbot/trip.feature b/features/testbot/trip.feature new file mode 100644 index 000000000..c9f944b26 --- /dev/null +++ b/features/testbot/trip.feature @@ -0,0 +1,86 @@ +@trip @testbot +Feature: Basic trip planning + + Background: + Given the profile "testbot" + Given a grid size of 10 meters + + Scenario: Testbot - Trip planning with less than 10 nodes + Given the node map + | a | b | + | d | c | + + And the ways + | nodes | + | ab | + | bc | + | cb | + | da | + + When I plan a trip I should get + | waypoints | trips | + | a,b,c,d | dcba | + + Scenario: Testbot - Trip planning with more than 10 nodes + Given the node map + | a | b | c | d | + | l | | | e | + | k | | | f | + | j | i | h | g | + + And the ways + | nodes | + | ab | + | bc | + | cb | + | de | + | ef | + | fg | + | gh | + | hi | + | ij | + | jk | + | kl | + | la | + + + When I plan a trip I should get + | waypoints | trips | + | a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc | + + Scenario: Testbot - Trip planning with multiple scc + Given the node map + | a | b | c | d | + | l | | | e | + | k | | | f | + | j | i | h | g | + | | | | | + | m | n | | | + | p | o | | | + + And the ways + | nodes | + | ab | + | bc | + | cb | + | de | + | ef | + | fg | + | gh | + | hi | + | ij | + | jk | + | kl | + | la | + | mn | + | no | + | op | + | pm | + + + When I plan a trip I should get + | waypoints | trips | + | a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p | cbalkjihgfedc,ponm | + + +