fuzzy ranges on routability tables, value shortcuts
This commit is contained in:
parent
62cc8f456c
commit
b3d517943a
@ -6,6 +6,12 @@ Given /^a grid size of (\d+) meters$/ do |meters|
|
||||
set_grid_size meters
|
||||
end
|
||||
|
||||
Given /^the shortcuts$/ do |table|
|
||||
table.hashes.each do |row|
|
||||
shortcuts_hash[ row['key'] ] = row['value']
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the node map$/ do |table|
|
||||
table.raw.each_with_index do |row,ri|
|
||||
row.each_with_index do |name,ci|
|
||||
|
@ -16,18 +16,21 @@ Then /^routability should be$/ do |table|
|
||||
elsif direction == 'backw' || direction == 'bothw'
|
||||
response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}")
|
||||
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] = "testing w#{i}, but got #{route}!?"
|
||||
elsif row[direction] =~ /\d+s/
|
||||
elsif want =~ /^\d+s/
|
||||
time = json['route_summary']['total_time']
|
||||
got[direction] = "#{time}s"
|
||||
end
|
||||
end
|
||||
if got[direction] != row[direction]
|
||||
if FuzzyMatch.match got[direction], want
|
||||
got[direction] = row[direction]
|
||||
else
|
||||
attempts << { :attempt => direction, :query => @query, :response => response }
|
||||
end
|
||||
end
|
||||
|
@ -53,31 +53,11 @@ When /^I route I should get$/ do |table|
|
||||
|
||||
ok = true
|
||||
row.keys.each do |key|
|
||||
if row[key].match /(.*)\s+~(.+)%$/ #percentage range: 100 ~5%
|
||||
margin = 1 - $2.to_f*0.01
|
||||
from = $1.to_f*margin
|
||||
to = $1.to_f/margin
|
||||
if got[key].to_f >= from && got[key].to_f <= to
|
||||
if FuzzyMatch.match got[key], row[key]
|
||||
got[key] = row[key]
|
||||
else
|
||||
ok = false
|
||||
end
|
||||
elsif row[key].match /(.*)\s+\+\-(.+)$/ #absolute range: 100 +-5
|
||||
margin = $2.to_f
|
||||
from = $1.to_f-margin
|
||||
to = $1.to_f+margin
|
||||
if got[key].to_f >= from && got[key].to_f <= to
|
||||
got[key] = row[key]
|
||||
else
|
||||
ok = false
|
||||
end
|
||||
elsif row[key] =~ /^\/(.*)\/$/ #regex: /a,b,.*/
|
||||
if got[key] =~ /#{$1}/
|
||||
got[key] = row[key]
|
||||
end
|
||||
else
|
||||
ok = row[key] == got[key]
|
||||
end
|
||||
end
|
||||
|
||||
unless ok
|
||||
|
@ -71,8 +71,15 @@ def build_ways_from_table table
|
||||
way << node5
|
||||
|
||||
tags = row.dup
|
||||
tags.delete 'forw'
|
||||
tags.delete 'backw'
|
||||
|
||||
# remove tags that describe expected test result
|
||||
tags.reject! do |k,v|
|
||||
k =~ /^forw\b/ ||
|
||||
k =~ /^backw\b/ ||
|
||||
k =~ /^bothw\b/
|
||||
end
|
||||
|
||||
##remove empty tags
|
||||
tags.reject! { |k,v| v=='' }
|
||||
|
||||
# sort tag keys in the form of 'node/....'
|
||||
|
26
features/support/fuzzy.rb
Normal file
26
features/support/fuzzy.rb
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
class FuzzyMatch
|
||||
|
||||
def self.match got, want
|
||||
if got == want
|
||||
return true
|
||||
elsif want.match /(.*)\s+~(.+)%$/ #percentage range: 100 ~5%
|
||||
margin = 1 - $2.to_f*0.01
|
||||
from = $1.to_f*margin
|
||||
to = $1.to_f/margin
|
||||
return got.to_f >= from && got.to_f <= to
|
||||
elsif want.match /(.*)\s+\+\-(.+)$/ #absolute range: 100 +-5
|
||||
margin = $2.to_f
|
||||
from = $1.to_f-margin
|
||||
to = $1.to_f+margin
|
||||
return got.to_f >= from && got.to_f <= to
|
||||
elsif want =~ /^\/(.*)\/$/ #regex: /a,b,.*/
|
||||
return got =~ /#{$1}/
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
3
features/support/shortcuts.rb
Normal file
3
features/support/shortcuts.rb
Normal file
@ -0,0 +1,3 @@
|
||||
def shortcuts_hash
|
||||
@shortcuts_hash ||= {}
|
||||
end
|
Loading…
Reference in New Issue
Block a user