osrm-backend/features/step_definitions/nearest.rb

52 lines
1.4 KiB
Ruby
Raw Normal View History

2013-02-03 14:17:06 -05:00
When /^I request nearest I should get$/ do |table|
reprocess
actual = []
2014-10-17 04:47:14 -04:00
OSRMLoader.load(self,"#{prepared_file}.osrm") do
2013-02-03 14:17:06 -05:00
table.hashes.each_with_index do |row,ri|
in_node = find_node_by_name row['in']
2013-02-03 14:17:06 -05:00
raise "*** unknown in-node '#{row['in']}" unless in_node
out_node = find_node_by_name row['out']
2013-02-03 14:17:06 -05:00
raise "*** unknown out-node '#{row['out']}" unless out_node
response = request_nearest("#{in_node.lat},#{in_node.lon}")
if response.code == "200" && response.body.empty? == false
json = JSON.parse response.body
if json['status'] == 0
coord = json['mapped_coordinate']
end
end
2013-02-03 14:17:06 -05:00
got = {'in' => row['in'], 'out' => coord }
2013-02-03 14:17:06 -05:00
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
2013-02-03 14:17:06 -05:00
unless ok
failed = { :attempt => 'nearest', :query => @query, :response => response }
log_fail row,got,[failed]
end
2013-02-03 14:17:06 -05:00
actual << got
end
end
2015-04-30 08:54:14 -04:00
table.diff! actual
2013-02-03 14:17:06 -05:00
end
2013-05-23 05:10:22 -04:00
When /^I request nearest (\d+) times I should get$/ do |n,table|
2013-02-03 14:17:06 -05:00
ok = true
n.to_i.times do
2013-05-23 05:10:22 -04:00
ok = false unless step "I request nearest I should get", table
2013-02-03 14:17:06 -05:00
end
ok
2013-09-18 02:16:19 -04:00
end