diff --git a/features/step_definitions/distance_matrix.rb b/features/step_definitions/distance_matrix.rb new file mode 100644 index 000000000..69ca4cc55 --- /dev/null +++ b/features/step_definitions/distance_matrix.rb @@ -0,0 +1,39 @@ +When /^I request a travel time matrix I should get$/ do |table| + + + raise "*** Top-left cell of matrix table must be empty" unless table.headers[0]=="" + + nodes = [] + column_headers = table.headers[1..-1] + row_headers = table.rows.map { |h| h.first } + unless column_headers==row_headers + raise "*** Column and row headers must match in matrix table, got #{column_headers.inspect} and #{row_headers.inspect}" + end + column_headers.each do |node_name| + node = find_node_by_name(node_name) + raise "*** unknown node '#{node_name}" unless node + nodes << node + end + + reprocess + actual = [] + actual << table.headers + OSRMLoader.load(self,"#{prepared_file}.osrm") do + + # compute matrix + params = @query_params + response = request_table nodes, params + if response.body.empty? == false + json = JSON.parse response.body + result = json['distance_table'] + end + + # compare actual and expected result, one row at a time + table.rows.each_with_index do |row,ri| + r = [row[0],result[ri]].flatten + r.map! { |v| v.to_s } + actual << r + end + end + table.routing_diff! actual +end diff --git a/features/support/route.rb b/features/support/route.rb index 745edc0fd..a8c78227e 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -43,6 +43,11 @@ def request_route waypoints, params={} request_path "viaroute", waypoints, defaults.merge(params) end +def request_table waypoints, params={} + defaults = { 'output' => 'json' } + request_path "table", waypoints, defaults.merge(params) +end + def got_route? response if response.code == "200" && !response.body.empty? json = JSON.parse response.body diff --git a/features/testbot/distance_matrix.feature b/features/testbot/distance_matrix.feature new file mode 100644 index 000000000..baa3b4e1e --- /dev/null +++ b/features/testbot/distance_matrix.feature @@ -0,0 +1,18 @@ +@matrix @testbot +Feature: Basic Distance Matrix + + Background: + Given the profile "testbot" + + Scenario: A single way with two nodes + Given the node map + | a | b | + + And the ways + | nodes | + | ab | + + When I request a travel time matrix I should get + | | a | b | + | a | 0 | 100 | + | b | 100 | 0 |