cuke: test speed, fix logging, clear log files on each run
This commit is contained in:
@@ -5,6 +5,7 @@ def test_routability_row i
|
||||
b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
|
||||
r = {}
|
||||
r[:response] = request_route direction=='forw' ? [a,b] : [b,a]
|
||||
r[:query] = @query
|
||||
r[:json] = JSON.parse(r[:response].body)
|
||||
|
||||
r[:status] = route_status r[:response]
|
||||
@@ -33,7 +34,7 @@ def test_routability_row i
|
||||
result['bothw'][key] = 'diff'
|
||||
end
|
||||
end
|
||||
|
||||
result['bothw'][:response] = [result['forw'][:response],result['backw'][:response]]
|
||||
result
|
||||
end
|
||||
|
||||
@@ -46,30 +47,30 @@ Then /^routability should be$/ do |table|
|
||||
end
|
||||
OSRMBackgroundLauncher.new("#{@osm_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,i|
|
||||
got = row.dup
|
||||
output_row = row.dup
|
||||
attempts = []
|
||||
result = test_routability_row i
|
||||
(['forw','backw','bothw'] & table.headers).each do |direction|
|
||||
directions = ['forw','backw','bothw']
|
||||
(directions & table.headers).each do |direction|
|
||||
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
|
||||
|
||||
case want
|
||||
when '', 'x'
|
||||
got[direction] = result[direction][:status].to_s
|
||||
output_row[direction] = result[direction][:status].to_s
|
||||
when /^\d+s/
|
||||
got[direction] = "#{result[direction][:time]}s"
|
||||
output_row[direction] = "#{result[direction][:time]}s"
|
||||
when /^\d+ km\/h/
|
||||
got[direction] = "#{result[direction][:speed]} km/h"
|
||||
output_row[direction] = "#{result[direction][:speed]} km/h"
|
||||
end
|
||||
|
||||
if FuzzyMatch.match got[direction], want
|
||||
got[direction] = row[direction]
|
||||
else
|
||||
# attempts << { :attempt => direction, :query => @query, :response => result[direction][:response] }
|
||||
if FuzzyMatch.match output_row[direction], want
|
||||
output_row[direction] = row[direction]
|
||||
end
|
||||
end
|
||||
|
||||
log_fail row,got,attempts if got != row
|
||||
actual << got
|
||||
if output_row != row
|
||||
log_fail row,output_row,result
|
||||
end
|
||||
actual << output_row
|
||||
end
|
||||
end
|
||||
table.routing_diff! actual
|
||||
|
||||
@@ -67,6 +67,17 @@ When /^I route I should get$/ do |table|
|
||||
raise "*** Time must be specied in seconds. (ex: 60s)" unless row['time'] =~ /\d+s/
|
||||
got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : ''
|
||||
end
|
||||
if table.headers.include?('speed')
|
||||
if row['speed'] != '' && instructions
|
||||
raise "*** Speed must be specied in km/h. (ex: 50 km/h)" unless row['speed'] =~ /\d+ km\/h/
|
||||
time = json['route_summary']['total_time']
|
||||
distance = json['route_summary']['total_distance']
|
||||
speed = time>0 ? (3.6*distance/time).to_i : nil
|
||||
got['speed'] = "#{speed} km/h"
|
||||
else
|
||||
got['speed'] = ''
|
||||
end
|
||||
end
|
||||
if table.headers.include? 'bearing'
|
||||
got['bearing'] = bearings
|
||||
end
|
||||
@@ -94,8 +105,7 @@ When /^I route I should get$/ do |table|
|
||||
end
|
||||
|
||||
unless ok
|
||||
failed = { :attempt => 'route', :query => @query, :response => response }
|
||||
log_fail row,got,[failed]
|
||||
log_fail row,got, { 'route' => {:query => @query, :response => response} }
|
||||
end
|
||||
|
||||
actual << got
|
||||
|
||||
Reference in New Issue
Block a user