diff --git a/features/step_definitions/data.rb b/features/step_definitions/data.rb index c2cf35c3b..c16adaacb 100644 --- a/features/step_definitions/data.rb +++ b/features/step_definitions/data.rb @@ -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| diff --git a/features/step_definitions/routability.rb b/features/step_definitions/routability.rb index d949d01b9..0af027a98 100644 --- a/features/step_definitions/routability.rb +++ b/features/step_definitions/routability.rb @@ -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 diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 17a3251c0..175b7e20c 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -53,30 +53,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 diff --git a/features/support/data.rb b/features/support/data.rb index f83bbd223..227a962fc 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -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/....' diff --git a/features/support/fuzzy.rb b/features/support/fuzzy.rb new file mode 100644 index 000000000..2758c1f82 --- /dev/null +++ b/features/support/fuzzy.rb @@ -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 + + diff --git a/features/support/shortcuts.rb b/features/support/shortcuts.rb new file mode 100644 index 000000000..20bc3c0fe --- /dev/null +++ b/features/support/shortcuts.rb @@ -0,0 +1,3 @@ +def shortcuts_hash + @shortcuts_hash ||= {} +end