initial support for testing distance matrices
This commit is contained in:
parent
0a884cc64a
commit
593808f24d
39
features/step_definitions/distance_matrix.rb
Normal file
39
features/step_definitions/distance_matrix.rb
Normal file
@ -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
|
@ -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
|
||||
|
18
features/testbot/distance_matrix.feature
Normal file
18
features/testbot/distance_matrix.feature
Normal file
@ -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 |
|
Loading…
Reference in New Issue
Block a user