Add tests for matching
This commit is contained in:
		
							parent
							
								
									028fad94af
								
							
						
					
					
						commit
						bc8666df83
					
				| @ -11,15 +11,18 @@ When /^I match I should get$/ do |table| | |||||||
|         trace = [] |         trace = [] | ||||||
|         timestamps = [] |         timestamps = [] | ||||||
|         if row['trace'] |         if row['trace'] | ||||||
|           row['trace'].split(',').each do |n| |           row['trace'].each_char do |n| | ||||||
|             node = find_node_by_name(n.strip) |             node = find_node_by_name(n.strip) | ||||||
|             raise "*** unknown waypoint node '#{n.strip}" unless node |             raise "*** unknown waypoint node '#{n.strip}" unless node | ||||||
|             trace << node |             trace << node | ||||||
|           end |           end | ||||||
|  |           if row['timestamps'] | ||||||
|  |               timestamps = row['timestamps'].split(" ").compact.map { |t| t.to_i} | ||||||
|  |           end | ||||||
|           got = {'trace' => row['trace'] } |           got = {'trace' => row['trace'] } | ||||||
|           response = request_matching trace, timestamps, params |           response = request_matching trace, timestamps, params | ||||||
|         else |         else | ||||||
|           raise "*** no waypoints" |           raise "*** no trace" | ||||||
|         end |         end | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
| @ -59,6 +62,10 @@ When /^I match I should get$/ do |table| | |||||||
|       encoded_result = "" |       encoded_result = "" | ||||||
|       extended_target = "" |       extended_target = "" | ||||||
|       row['matchings'].split(',').each_with_index do |sub, sub_idx| |       row['matchings'].split(',').each_with_index do |sub, sub_idx| | ||||||
|  |         if sub_idx >= sub_matchings.length | ||||||
|  |           ok = false | ||||||
|  |           break | ||||||
|  |         end | ||||||
|         sub.length.times do |node_idx| |         sub.length.times do |node_idx| | ||||||
|           node = find_node_by_name(sub[node_idx]) |           node = find_node_by_name(sub[node_idx]) | ||||||
|           out_node = sub_matchings[sub_idx][node_idx] |           out_node = sub_matchings[sub_idx][node_idx] | ||||||
| @ -66,7 +73,7 @@ When /^I match I should get$/ do |table| | |||||||
|             encoded_result += sub[node_idx] |             encoded_result += sub[node_idx] | ||||||
|             extended_target += sub[node_idx] |             extended_target += sub[node_idx] | ||||||
|           else |           else | ||||||
|             encoded_result += "[#{out_node[0]},#{out_node[1]}]" |             encoded_result += "? [#{out_node[0]},#{out_node[1]}]" | ||||||
|             extended_target += "#{sub[node_idx]} [#{node.lat},#{node.lon}]" |             extended_target += "#{sub[node_idx]} [#{node.lat},#{node.lon}]" | ||||||
|             ok = false |             ok = false | ||||||
|           end |           end | ||||||
| @ -74,6 +81,7 @@ When /^I match I should get$/ do |table| | |||||||
|       end |       end | ||||||
|       if ok |       if ok | ||||||
|         got['matchings'] = row['matchings'] |         got['matchings'] = row['matchings'] | ||||||
|  |         got['timestamps'] = row['timestamps'] | ||||||
|       else |       else | ||||||
|         got['matchings'] = encoded_result |         got['matchings'] = encoded_result | ||||||
|         row['matchings'] = extended_target |         row['matchings'] = extended_target | ||||||
|  | |||||||
| @ -1,21 +1,17 @@ | |||||||
| require 'net/http' | require 'net/http' | ||||||
| 
 | 
 | ||||||
| HOST = "http://127.0.0.1:#{OSRM_PORT}" | HOST = "http://127.0.0.1:#{OSRM_PORT}" | ||||||
| DESTINATION_REACHED = 15      #OSRM instruction code |  | ||||||
| 
 |  | ||||||
| class Hash |  | ||||||
|   def to_param(namespace = nil) |  | ||||||
|     collect do |key, value| |  | ||||||
|       "#{key}=#{value}" |  | ||||||
|     end.sort |  | ||||||
|   end |  | ||||||
| end |  | ||||||
| 
 | 
 | ||||||
| def request_matching trace=[], timestamps=[], options={} | def request_matching trace=[], timestamps=[], options={} | ||||||
|   defaults = { 'output' => 'json' } |   defaults = { 'output' => 'json' } | ||||||
|   locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" } |   locs = trace.compact.map { |w| "loc=#{w.lat},#{w.lon}" } | ||||||
|   ts = timestamps.compact.map { |t| "t=#{t}" } |   ts = timestamps.compact.map { |t| "t=#{t}" } | ||||||
|   params = (locs + ts + defaults.merge(options).to_param).join('&') |   if ts.length > 0 | ||||||
|  |     trace_params = locs.zip(ts).map { |a| a.join('&')} | ||||||
|  |   else | ||||||
|  |     trace_params = locs | ||||||
|  |   end | ||||||
|  |   params = (trace_params + defaults.merge(options).to_param).join('&') | ||||||
|   params = nil if params=="" |   params = nil if params=="" | ||||||
|   uri = URI.parse ["#{HOST}/match", params].compact.join('?') |   uri = URI.parse ["#{HOST}/match", params].compact.join('?') | ||||||
|   @query = uri.to_s |   @query = uri.to_s | ||||||
|  | |||||||
							
								
								
									
										55
									
								
								features/testbot/matching.feature
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								features/testbot/matching.feature
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | |||||||
|  | @match @testbot | ||||||
|  | Feature: Basic Map Matching | ||||||
|  | 
 | ||||||
|  |     Background: | ||||||
|  |         Given the profile "testbot" | ||||||
|  |         Given a grid size of 10 meters | ||||||
|  | 
 | ||||||
|  |     Scenario: Testbot - Map matching with trace splitting | ||||||
|  |         Given the node map | ||||||
|  |             | a | b | c | d | | ||||||
|  |             |   |   | e |   | | ||||||
|  | 
 | ||||||
|  |         And the ways | ||||||
|  |             | nodes | oneway | | ||||||
|  |             | abcd  | no     | | ||||||
|  | 
 | ||||||
|  |         When I match I should get | ||||||
|  |             | trace | timestamps | matchings | | ||||||
|  |             | abcd  | 0 1 42 43  | ab,cd     | | ||||||
|  | 
 | ||||||
|  |     Scenario: Testbot - Map matching with small distortion | ||||||
|  |         Given the node map | ||||||
|  |             | a | b | c | d | e | | ||||||
|  |             |   | f |   |   |   | | ||||||
|  |             |   |   |   |   |   | | ||||||
|  |             |   |   |   |   |   | | ||||||
|  |             |   |   |   |   |   | | ||||||
|  |             |   | h |   |   | k | | ||||||
|  | 
 | ||||||
|  |         # The second way does not need to be a oneway | ||||||
|  |         # but the grid spacing triggers the uturn | ||||||
|  |         # detection on f | ||||||
|  |         And the ways | ||||||
|  |             | nodes | oneway | | ||||||
|  |             | abcde | no     | | ||||||
|  |             | bfhke | yes    | | ||||||
|  | 
 | ||||||
|  |         When I match I should get | ||||||
|  |             | trace  | matchings | | ||||||
|  |             | afcde  | abcde     | | ||||||
|  | 
 | ||||||
|  |     Scenario: Testbot - Map matching with oneways | ||||||
|  |         Given the node map | ||||||
|  |             | a | b | c | d | | ||||||
|  |             | e | f | g | h | | ||||||
|  | 
 | ||||||
|  |         And the ways | ||||||
|  |             | nodes | oneway | | ||||||
|  |             | abcd  | yes    | | ||||||
|  |             | hgfe  | yes    | | ||||||
|  | 
 | ||||||
|  |         When I match I should get | ||||||
|  |             | trace | matchings | | ||||||
|  |             | dcba  | hgfe      | | ||||||
|  | 
 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user