osrm-backend/features/step_definitions/nearest.rb
Patrick Niklaus 78ac3cffde Add max values for viaroute and trip and reorganize return code handling
"status" is now always:
 - 200 if the request was successful
 - 207 if the result is empty (no path found)
 - 400 if the request is invalid

 viaroute and trip now have a maximum of 500 and 100 locations
 respectively. Override with the --max-viaroute-size and --max-trip-size
 parameters.
2015-12-17 04:14:34 +01:00

52 lines
1.4 KiB
Ruby

When /^I request nearest I should get$/ do |table|
reprocess
actual = []
OSRMLoader.load(self,"#{prepared_file}.osrm") do
table.hashes.each_with_index do |row,ri|
in_node = find_node_by_name row['in']
raise "*** unknown in-node '#{row['in']}" unless in_node
out_node = find_node_by_name row['out']
raise "*** unknown out-node '#{row['out']}" unless out_node
response = request_nearest in_node, @query_params
if response.code == "200" && response.body.empty? == false
json = JSON.parse response.body
if json['status'] == 200
coord = json['mapped_coordinate']
end
end
got = {'in' => row['in'], 'out' => coord }
ok = true
row.keys.each do |key|
if key=='out'
if FuzzyMatch.match_location coord, out_node
got[key] = row[key]
else
row[key] = "#{row[key]} [#{out_node.lat},#{out_node.lon}]"
ok = false
end
end
end
unless ok
failed = { :attempt => 'nearest', :query => @query, :response => response }
log_fail row,got,[failed]
end
actual << got
end
end
table.diff! actual
end
When /^I request nearest (\d+) times I should get$/ do |n,table|
ok = true
n.to_i.times do
ok = false unless step "I request nearest I should get", table
end
ok
end