Add tests for matching

This commit is contained in:
Patrick Niklaus 2015-03-08 01:32:13 +01:00
parent 028fad94af
commit bc8666df83
3 changed files with 76 additions and 17 deletions

View File

@ -11,15 +11,18 @@ When /^I match I should get$/ do |table|
trace = []
timestamps = []
if row['trace']
row['trace'].split(',').each do |n|
row['trace'].each_char do |n|
node = find_node_by_name(n.strip)
raise "*** unknown waypoint node '#{n.strip}" unless node
trace << node
end
if row['timestamps']
timestamps = row['timestamps'].split(" ").compact.map { |t| t.to_i}
end
got = {'trace' => row['trace'] }
response = request_matching trace, timestamps, params
else
raise "*** no waypoints"
raise "*** no trace"
end
end
@ -59,6 +62,10 @@ When /^I match I should get$/ do |table|
encoded_result = ""
extended_target = ""
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|
node = find_node_by_name(sub[node_idx])
out_node = sub_matchings[sub_idx][node_idx]
@ -66,17 +73,18 @@ When /^I match I should get$/ do |table|
encoded_result += sub[node_idx]
extended_target += sub[node_idx]
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}]"
ok = false
end
end
end
if ok
got['matchings'] = row['matchings']
got['matchings'] = row['matchings']
got['timestamps'] = row['timestamps']
else
got['matchings'] = encoded_result
row['matchings'] = extended_target
got['matchings'] = encoded_result
row['matchings'] = extended_target
log_fail row,got, { 'matching' => {:query => @query, :response => response} }
end

View File

@ -1,21 +1,17 @@
require 'net/http'
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={}
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}" }
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==""
uri = URI.parse ["#{HOST}/match", params].compact.join('?')
@query = uri.to_s

View 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 |