diff --git a/features/locate/locate.feature b/features/locate/locate.feature new file mode 100644 index 000000000..cbf6b200f --- /dev/null +++ b/features/locate/locate.feature @@ -0,0 +1,179 @@ +@locate +Feature: Locate - return nearest node + + Background: + Given the profile "testbot" + + Scenario: Locate - two ways crossing + Given the node map + | | | 0 | c | 1 | | | + | | | | | | | | + | 7 | | | n | | | 2 | + | a | | k | x | m | | b | + | 6 | | | l | | | 3 | + | | | | | | | | + | | | 5 | d | 4 | | | + + And the ways + | nodes | + | axb | + | cxd | + + When I request locate I should get + | in | out | + | 0 | c | + | 1 | c | + | 2 | b | + | 3 | b | + | 4 | d | + | 5 | d | + | 6 | a | + | 7 | a | + | a | a | + | b | b | + | c | c | + | d | d | + | k | x | + | l | x | + | m | x | + | n | x | + + Scenario: Locate - inside a triangle + Given the node map + | | | | | | c | | | | | | + | | | | | | 7 | | | | | | + | | | | y | | | | z | | | | + | | | 5 | | 0 | | 1 | | 8 | | | + | 6 | | | 2 | | 3 | | 4 | | | 9 | + | a | | | x | | u | | w | | | b | + + And the ways + | nodes | + | ab | + | bc | + | ca | + + When I request locate I should get + | in | out | + | 0 | c | + | 1 | c | + | 2 | a | + | 3 | c | + | 4 | b | + | 5 | a | + | 6 | a | + | 7 | c | + | 8 | b | + | 9 | b | + | x | a | + | y | c | + | z | c | + | w | b | + + Scenario: Nearest - easy-west way + Given the node map + | 3 | 4 | | 5 | 6 | + | 2 | a | x | b | 7 | + | 1 | 0 | | 9 | 8 | + + And the ways + | nodes | + | ab | + + When I request nearest I should get + | in | out | + | 0 | a | + | 1 | a | + | 2 | a | + | 3 | a | + | 4 | a | + | 5 | b | + | 6 | b | + | 7 | b | + | 8 | b | + | 9 | b | + + Scenario: Nearest - north-south way + Given the node map + | 1 | 2 | 3 | + | 0 | a | 4 | + | | x | | + | 9 | b | 5 | + | 8 | 7 | 6 | + + And the ways + | nodes | + | ab | + + When I request nearest I should get + | in | out | + | 0 | a | + | 1 | a | + | 2 | a | + | 3 | a | + | 4 | a | + | 5 | b | + | 6 | b | + | 7 | b | + | 8 | b | + | 9 | b | + + Scenario: Nearest - diagonal 1 + Given the node map + | 2 | | 3 | | | | + | | a | | 4 | | | + | 1 | | x | | 5 | | + | | 0 | | y | | 6 | + | | | 9 | | b | | + | | | | 8 | | 7 | + + And the ways + | nodes | + | axyb | + + When I request nearest I should get + | in | out | + | 0 | x | + | 1 | a | + | 2 | a | + | 3 | a | + | 4 | x | + | 5 | y | + | 6 | b | + | 7 | b | + | 8 | b | + | 9 | y | + | a | a | + | b | b | + | x | x | + | y | y | + + Scenario: Nearest - diagonal 2 + Given the node map + | | | | 6 | | 7 | + | | | 5 | | b | | + | | 4 | | y | | 8 | + | 3 | | x | | 9 | | + | | a | | 0 | | | + | 2 | | 1 | | | | + + And the ways + | nodes | + | ab | + + When I request nearest I should get + | in | out | + | 0 | x | + | 1 | a | + | 2 | a | + | 3 | a | + | 4 | x | + | 5 | y | + | 6 | b | + | 7 | b | + | 8 | b | + | 9 | y | + | a | a | + | b | b | + | x | x | + | y | y | diff --git a/features/step_definitions/locate.rb b/features/step_definitions/locate.rb new file mode 100644 index 000000000..a47f3e045 --- /dev/null +++ b/features/step_definitions/locate.rb @@ -0,0 +1,51 @@ +When /^I request locate I should get$/ do |table| + reprocess + actual = [] + OSRMLauncher.new do + table.hashes.each_with_index do |row,ri| + in_node = find_node_by_name row['in'] + raise "*** unknown in-node '#{row['in']}" unless in_node + + out_node = find_node_by_name row['out'] + raise "*** unknown out-node '#{row['out']}" unless out_node + + response = request_locate("#{in_node.lat},#{in_node.lon}") + if response.code == "200" && response.body.empty? == false + json = JSON.parse response.body + if json['status'] == 0 + coord = json['mapped_coordinate'] + end + end + + got = {'in' => row['in'], 'out' => coord } + + ok = true + row.keys.each do |key| + if key=='out' + if FuzzyMatch.match_location coord, out_node + got[key] = row[key] + else + row[key] = "#{row[key]} [#{out_node.lat},#{out_node.lon}]" + ok = false + end + end + end + + unless ok + failed = { :attempt => 'locate', :query => @query, :response => response } + log_fail row,got,[failed] + end + + actual << got + end + end + table.routing_diff! actual +end + +When /^I request locate (\d+) times I should get$/ do |n,table| + ok = true + n.to_i.times do + ok = false unless step "I request locate I should get", table + end + ok +end \ No newline at end of file diff --git a/features/support/locate.rb b/features/support/locate.rb new file mode 100644 index 000000000..b7dc55f6d --- /dev/null +++ b/features/support/locate.rb @@ -0,0 +1,17 @@ +require 'net/http' + +def request_locate_url path + @query = path + uri = URI.parse "#{HOST}/#{path}" + Timeout.timeout(REQUEST_TIMEOUT) do + Net::HTTP.get_response uri + end +rescue Errno::ECONNREFUSED => e + raise "*** osrm-routed is not running." +rescue Timeout::Error + raise "*** osrm-routed did not respond." +end + +def request_locate a + request_locate_url "locate?loc=#{a}" +end