osrm-backend/features/step_definitions/routability.rb

79 lines
2.5 KiB
Ruby
Raw Normal View History

def test_routability_row i
result = {}
['forw','backw'].each do |direction|
a = Location.new @origin[0]+(1+WAY_SPACING*i)*@zoom, @origin[1]
b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
r = {}
2015-12-08 17:00:11 -05:00
r[:response] = request_route (direction=='forw' ? [a,b] : [b,a]), [], @query_params
r[:query] = @query
r[:json] = JSON.parse(r[:response].body)
r[:status] = (route_status r[:response]) == 200 ? 'x' : nil
if r[:status] then
r[:route] = way_list r[:json]['route_instructions']
if r[:route]=="w#{i}"
r[:time] = r[:json]['route_summary']['total_time']
r[:distance] = r[:json]['route_summary']['total_distance']
r[:speed] = r[:time]>0 ? (3.6*r[:distance]/r[:time]).to_i : nil
else
# if we hit the wrong way segment, we assume it's
# because the one we tested was not unroutable
r[:status] = nil
end
end
result[direction] = r
end
# check if forw and backw returned the same values
result['bothw'] = {}
[:status,:time,:distance,:speed].each do |key|
if result['forw'][key] == result['backw'][key]
result['bothw'][key] = result['forw'][key]
else
result['bothw'][key] = 'diff'
end
end
result
end
2012-12-16 07:36:47 -05:00
Then /^routability should be$/ do |table|
build_ways_from_table table
reprocess
actual = []
if table.headers&["forw","backw","bothw"] == []
raise "*** routability tabel must contain either 'forw', 'backw' or 'bothw' column"
end
2014-10-17 04:47:14 -04:00
OSRMLoader.load(self,"#{prepared_file}.osrm") do
2012-12-16 07:36:47 -05:00
table.hashes.each_with_index do |row,i|
output_row = row.dup
2012-12-16 07:36:47 -05:00
attempts = []
result = test_routability_row i
directions = ['forw','backw','bothw']
(directions & table.headers).each do |direction|
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
case want
when '', 'x'
2014-08-19 10:39:10 -04:00
output_row[direction] = result[direction][:status] ? result[direction][:status].to_s : ''
when /^\d+s/
2014-08-12 08:18:02 -04:00
output_row[direction] = result[direction][:time] ? "#{result[direction][:time]}s" : ''
when /^\d+ km\/h/
2014-08-12 08:18:02 -04:00
output_row[direction] = result[direction][:speed] ? "#{result[direction][:speed]} km/h" : ''
else
raise "*** Unknown expectation format: #{want}"
end
if FuzzyMatch.match output_row[direction], want
output_row[direction] = row[direction]
2012-12-16 07:36:47 -05:00
end
end
if output_row != row
log_fail row,output_row,result
end
actual << output_row
2012-12-16 07:36:47 -05:00
end
end
2015-04-30 08:54:14 -04:00
table.diff! actual
2012-12-16 07:36:47 -05:00
end