2012-02-14 11:21:07 -05:00
|
|
|
When /^I route I should get$/ do |table|
|
|
|
|
reprocess
|
|
|
|
actual = []
|
|
|
|
OSRMLauncher.new do
|
|
|
|
table.hashes.each_with_index do |row,ri|
|
|
|
|
from_node = @name_node_hash[ row['from'] ]
|
|
|
|
raise "*** unknown from-node '#{row['from']}" unless from_node
|
|
|
|
to_node = @name_node_hash[ row['to'] ]
|
|
|
|
raise "*** unknown to-node '#{row['to']}" unless to_node
|
|
|
|
response = request_route("#{from_node.lat},#{from_node.lon}", "#{to_node.lat},#{to_node.lon}")
|
|
|
|
if response.code == "200" && response.body.empty? == false
|
|
|
|
json = JSON.parse response.body
|
|
|
|
if json['status'] == 0
|
|
|
|
instructions = way_list json['route_instructions']
|
2012-05-14 12:33:05 -04:00
|
|
|
bearings = bearing_list json['route_instructions']
|
|
|
|
compasses = compass_list json['route_instructions']
|
2012-12-09 12:21:33 -05:00
|
|
|
turns = turn_list json['route_instructions']
|
2012-02-14 11:21:07 -05:00
|
|
|
end
|
|
|
|
end
|
2012-02-19 14:36:29 -05:00
|
|
|
|
2012-02-14 11:21:07 -05:00
|
|
|
got = {'from' => row['from'], 'to' => row['to'] }
|
|
|
|
if table.headers.include? 'start'
|
|
|
|
got['start'] = instructions ? json['route_summary']['start_point'] : nil
|
|
|
|
end
|
|
|
|
if table.headers.include? 'end'
|
|
|
|
got['end'] = instructions ? json['route_summary']['end_point'] : nil
|
|
|
|
end
|
|
|
|
if table.headers.include? 'route'
|
|
|
|
got['route'] = (instructions || '').strip
|
2012-10-01 12:30:32 -04:00
|
|
|
if table.headers.include?('distance')
|
|
|
|
if row['distance']!=''
|
|
|
|
raise "*** Distance must be specied in meters. (ex: 250m)" unless row['distance'] =~ /\d+m/
|
|
|
|
end
|
2012-10-03 03:49:45 -04:00
|
|
|
got['distance'] = instructions ? "#{json['route_summary']['total_distance'].to_s}m" : ''
|
2012-02-19 14:36:29 -05:00
|
|
|
end
|
2012-10-01 12:30:32 -04:00
|
|
|
if table.headers.include?('time')
|
2012-10-01 12:13:44 -04:00
|
|
|
raise "*** Time must be specied in seconds. (ex: 60s)" unless row['time'] =~ /\d+s/
|
2012-09-27 10:31:09 -04:00
|
|
|
got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : ''
|
2012-02-19 14:36:29 -05:00
|
|
|
end
|
2012-05-14 12:33:05 -04:00
|
|
|
if table.headers.include? 'bearing'
|
|
|
|
got['bearing'] = bearings
|
|
|
|
end
|
|
|
|
if table.headers.include? 'compass'
|
|
|
|
got['compass'] = compasses
|
|
|
|
end
|
2012-12-09 12:21:33 -05:00
|
|
|
if table.headers.include? 'turns'
|
|
|
|
got['turns'] = turns
|
|
|
|
end
|
2012-02-18 11:50:04 -05:00
|
|
|
end
|
|
|
|
|
2012-08-31 02:10:55 -04:00
|
|
|
ok = true
|
|
|
|
row.keys.each do |key|
|
2012-12-03 04:59:24 -05:00
|
|
|
if row[key].match /(.*)\s+~(.+)%$/ #percentage range: 100 ~5%
|
2012-08-31 02:10:55 -04:00
|
|
|
margin = 1 - $2.to_f*0.01
|
|
|
|
from = $1.to_f*margin
|
|
|
|
to = $1.to_f/margin
|
2012-10-10 11:51:10 -04:00
|
|
|
if got[key].to_f >= from && got[key].to_f <= to
|
2012-08-31 02:10:55 -04:00
|
|
|
got[key] = row[key]
|
|
|
|
else
|
|
|
|
ok = false
|
|
|
|
end
|
2012-12-03 04:59:24 -05:00
|
|
|
elsif row[key].match /(.*)\s+\+\-(.+)$/ #absolute range: 100 +-5
|
2012-08-31 02:10:55 -04:00
|
|
|
margin = $2.to_f
|
|
|
|
from = $1.to_f-margin
|
|
|
|
to = $1.to_f+margin
|
2012-10-10 11:51:10 -04:00
|
|
|
if got[key].to_f >= from && got[key].to_f <= to
|
2012-08-31 02:10:55 -04:00
|
|
|
got[key] = row[key]
|
|
|
|
else
|
|
|
|
ok = false
|
|
|
|
end
|
2012-12-03 04:59:24 -05:00
|
|
|
elsif row[key] =~ /^\/(.*)\/$/ #regex: /a,b,.*/
|
|
|
|
if got[key] =~ /#{$1}/
|
|
|
|
got[key] = row[key]
|
|
|
|
end
|
2012-08-31 02:10:55 -04:00
|
|
|
else
|
2012-09-19 12:35:45 -04:00
|
|
|
ok = row[key] == got[key]
|
2012-08-31 02:10:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
unless ok
|
2012-02-18 11:50:04 -05:00
|
|
|
failed = { :attempt => 'route', :query => @query, :response => response }
|
2012-02-14 11:21:07 -05:00
|
|
|
log_fail row,got,[failed]
|
|
|
|
end
|
2012-02-19 14:36:29 -05:00
|
|
|
|
2012-02-14 11:21:07 -05:00
|
|
|
actual << got
|
|
|
|
end
|
|
|
|
end
|
2012-02-18 08:49:02 -05:00
|
|
|
table.routing_diff! actual
|
2012-02-14 11:21:07 -05:00
|
|
|
end
|
2012-12-15 06:34:53 -05:00
|
|
|
|
|
|
|
When /^I route (\d+) times I should get$/ do |n,table|
|
|
|
|
ok = true
|
|
|
|
n.to_i.times do
|
|
|
|
ok = false unless step "I route I should get", table
|
|
|
|
end
|
|
|
|
ok
|
|
|
|
end
|