fuzzy matching in routability tables, ported from opposite branch

This commit is contained in:
Emil Tin
2013-02-04 10:31:35 +01:00
parent bb1064ac42
commit d67ac1a708
5 changed files with 22 additions and 29 deletions
+6
View File
@@ -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|
+5 -2
View File
@@ -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
+3 -23
View File
@@ -50,30 +50,10 @@ 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
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
if FuzzyMatch.match got[key], row[key]
got[key] = row[key]
else
ok = row[key] == got[key]
ok = false
end
end