fuzzy ranges on routability tables, value shortcuts
This commit is contained in:
@@ -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/....'
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
def shortcuts_hash
|
||||
@shortcuts_hash ||= {}
|
||||
end
|
||||
Reference in New Issue
Block a user