cuke: improve routability tables, test for speed

This commit is contained in:
Emil Tin
2014-03-27 00:53:27 +01:00
parent b0ce9e4af7
commit cb1b824a75
5 changed files with 114 additions and 67 deletions
+57 -28
View File
@@ -1,3 +1,42 @@
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 = {}
r[:response] = request_route direction=='forw' ? [a,b] : [b,a]
r[:json] = JSON.parse(r[:response].body)
r[:status] = route_status r[:response]
if r[:status].empty? == false
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 = {}
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
Then /^routability should be$/ do |table|
build_ways_from_table table
reprocess
@@ -9,36 +48,26 @@ Then /^routability should be$/ do |table|
table.hashes.each_with_index do |row,i|
got = row.dup
attempts = []
['forw','backw','bothw'].each do |direction|
if table.headers.include? direction
if direction == 'forw' || direction == 'bothw'
a = Location.new @origin[0]+(1+WAY_SPACING*i)*@zoom, @origin[1]
b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
response = request_route [a,b]
elsif direction == 'backw' || direction == 'bothw'
a = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
b = Location.new @origin[0]+(1+WAY_SPACING*i)*@zoom, @origin[1]
response = request_route [a,b]
end
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
got[direction] = route_status response
json = JSON.parse(response.body)
if got[direction].empty? == false
route = way_list json['route_instructions']
if route != "w#{i}"
got[direction] = ''
elsif want =~ /^\d+s/
time = json['route_summary']['total_time']
got[direction] = "#{time}s"
end
end
if FuzzyMatch.match got[direction], want
got[direction] = row[direction]
else
attempts << { :attempt => direction, :query => @query, :response => response }
end
result = test_routability_row i
(['forw','backw','bothw'] & 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
when /^\d+s/
got[direction] = "#{result[direction][:time]}s"
when /^\d+ km\/h/
got[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] }
end
end
log_fail row,got,attempts if got != row
actual << got
end