Rewrite cucumber test suite in JS
This commit is contained in:
@@ -0,0 +1,273 @@
|
||||
var util = require('util');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var d3 = require('d3-queue');
|
||||
var OSM = require('../support/build_osm');
|
||||
|
||||
module.exports = function () {
|
||||
this.Given(/^the profile "([^"]*)"$/, (profile, callback) => {
|
||||
this.setProfile(profile, callback);
|
||||
});
|
||||
|
||||
this.Given(/^the extract extra arguments "(.*?)"$/, (args, callback) => {
|
||||
this.setExtractArgs(args);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^the contract extra arguments "(.*?)"$/, (args, callback) => {
|
||||
this.setContractArgs(args);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^a grid size of (\d+) meters$/, (meters, callback) => {
|
||||
this.setGridSize(meters);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^the origin ([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)$/, (lat, lon, callback) => {
|
||||
this.setOrigin([parseFloat(lon), parseFloat(lat)]);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^the shortcuts$/, (table, callback) => {
|
||||
var q = d3.queue();
|
||||
|
||||
var addShortcut = (row, cb) => {
|
||||
this.shortcutsHash[row.key] = row.value;
|
||||
cb();
|
||||
};
|
||||
|
||||
table.hashes().forEach((row) => {
|
||||
q.defer(addShortcut, row);
|
||||
});
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the node map$/, (table, callback) => {
|
||||
var q = d3.queue();
|
||||
|
||||
var addNode = (name, ri, ci, cb) => {
|
||||
if (name) {
|
||||
if (name.length !== 1) throw new Error(util.format('*** node invalid name %s, must be single characters', name));
|
||||
if (!name.match(/[a-z0-9]/)) throw new Error(util.format('*** invalid node name %s, must me alphanumeric', name));
|
||||
|
||||
var lonLat;
|
||||
if (name.match(/[a-z]/)) {
|
||||
if (this.nameNodeHash[name]) throw new Error(util.format('*** duplicate node %s', name));
|
||||
lonLat = this.tableCoordToLonLat(ci, ri);
|
||||
this.addOSMNode(name, lonLat[0], lonLat[1], null);
|
||||
} else {
|
||||
if (this.locationHash[name]) throw new Error(util.format('*** duplicate node %s'), name);
|
||||
lonLat = this.tableCoordToLonLat(ci, ri);
|
||||
this.addLocation(name, lonLat[0], lonLat[1], null);
|
||||
}
|
||||
|
||||
cb();
|
||||
}
|
||||
else cb();
|
||||
};
|
||||
|
||||
table.raw().forEach((row, ri) => {
|
||||
row.forEach((name, ci) => {
|
||||
q.defer(addNode, name, ri, ci);
|
||||
});
|
||||
});
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the node locations$/, (table, callback) => {
|
||||
var q = d3.queue();
|
||||
|
||||
var addNodeLocations = (row, cb) => {
|
||||
var name = row.node;
|
||||
if (this.findNodeByName(name)) throw new Error(util.format('*** duplicate node %s'), name);
|
||||
|
||||
if (name.match(/[a-z]/)) {
|
||||
var id = row.id && parseInt(row.id);
|
||||
this.addOSMNode(name, row.lon, row.lat, id);
|
||||
} else {
|
||||
this.addLocation(name, row.lon, row.lat);
|
||||
}
|
||||
|
||||
cb();
|
||||
};
|
||||
|
||||
table.hashes().forEach((row) => q.defer(addNodeLocations, row));
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the nodes$/, (table, callback) => {
|
||||
var q = d3.queue();
|
||||
|
||||
var addNode = (row, cb) => {
|
||||
var name = row.node,
|
||||
node = this.findNodeByName(name);
|
||||
delete row.node;
|
||||
if (!node) throw new Error(util.format('*** unknown node %s'), name);
|
||||
for (var key in row) {
|
||||
node.addTag(key, row[key]);
|
||||
}
|
||||
cb();
|
||||
};
|
||||
|
||||
table.hashes().forEach((row) => q.defer(addNode, row));
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the ways$/, (table, callback) => {
|
||||
if (this.osm_str) throw new Error('*** Map data already defined - did you pass an input file in this scenario?');
|
||||
|
||||
var q = d3.queue();
|
||||
|
||||
var addWay = (row, cb) => {
|
||||
var way = new OSM.Way(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
|
||||
|
||||
var nodes = row.nodes;
|
||||
if (this.nameWayHash.nodes) throw new Error(util.format('*** duplicate way %s', nodes));
|
||||
|
||||
for (var i=0; i<nodes.length; i++) {
|
||||
var c = nodes[i];
|
||||
if (!c.match(/[a-z]/)) throw new Error(util.format('*** ways can only use names a-z (%s)', c));
|
||||
var node = this.findNodeByName(c);
|
||||
if (!node) throw new Error(util.format('*** unknown node %s', c));
|
||||
way.addNode(node);
|
||||
}
|
||||
|
||||
var tags = {
|
||||
highway: 'primary'
|
||||
};
|
||||
|
||||
for (var key in row) {
|
||||
tags[key] = row[key];
|
||||
}
|
||||
|
||||
delete tags.nodes;
|
||||
|
||||
if (row.highway === '(nil)') delete tags.highway;
|
||||
|
||||
if (row.name === undefined)
|
||||
tags.name = nodes;
|
||||
else if (row.name === '""' || row.name === "''") // eslint-disable-line quotes
|
||||
tags.name = '';
|
||||
else if (row.name === '' || row.name === '(nil)')
|
||||
delete tags.name;
|
||||
else
|
||||
tags.name = row.name;
|
||||
|
||||
way.setTags(tags);
|
||||
this.OSMDB.addWay(way);
|
||||
this.nameWayHash[nodes] = way;
|
||||
cb();
|
||||
};
|
||||
|
||||
table.hashes().forEach((row) => q.defer(addWay, row));
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the relations$/, (table, callback) => {
|
||||
if (this.osm_str) throw new Error('*** Map data already defined - did you pass an input file in this scenario?');
|
||||
|
||||
var q = d3.queue();
|
||||
|
||||
var addRelation = (row, cb) => {
|
||||
var relation = new OSM.Relation(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
|
||||
|
||||
for (var key in row) {
|
||||
var isNode = key.match(/^node:(.*)/),
|
||||
isWay = key.match(/^way:(.*)/),
|
||||
isColonSeparated = key.match(/^(.*):(.*)/);
|
||||
if (isNode) {
|
||||
row[key].split(',').map(function(v) { return v.trim(); }).forEach((nodeName) => {
|
||||
if (nodeName.length !== 1) throw new Error(util.format('*** invalid relation node member "%s"'), nodeName);
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown relation node member "%s"'), nodeName);
|
||||
relation.addMember('node', node.id, isNode[1]);
|
||||
});
|
||||
} else if (isWay) {
|
||||
row[key].split(',').map(function(v) { return v.trim(); }).forEach((wayName) => {
|
||||
var way = this.findWayByName(wayName);
|
||||
if (!way) throw new Error(util.format('*** unknown relation way member "%s"'), wayName);
|
||||
relation.addMember('way', way.id, isWay[1]);
|
||||
});
|
||||
} else if (isColonSeparated && isColonSeparated[1] !== 'restriction') {
|
||||
throw new Error(util.format('*** unknown relation member type "%s:%s", must be either "node" or "way"'), isColonSeparated[1], isColonSeparated[2]);
|
||||
} else {
|
||||
relation.addTag(key, row[key]);
|
||||
}
|
||||
}
|
||||
relation.uid = this.OSM_UID;
|
||||
|
||||
this.OSMDB.addRelation(relation);
|
||||
|
||||
cb();
|
||||
};
|
||||
|
||||
table.hashes().forEach((row) => q.defer(addRelation, row));
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the input file ([^"]*)$/, (file, callback) => {
|
||||
if (path.extname(file) !== '.osm') throw new Error('*** Input file must be in .osm format');
|
||||
fs.readFile(file, 'utf8', (err, data) => {
|
||||
if (!err) this.osm_str = data.toString();
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
|
||||
this.Given(/^the raster source$/, (data, callback) => {
|
||||
fs.writeFile(path.resolve(this.TEST_FOLDER, 'rastersource.asc'), data, callback);
|
||||
});
|
||||
|
||||
this.Given(/^the speed file$/, (data, callback) => {
|
||||
fs.writeFile(path.resolve(this.TEST_FOLDER, 'speeds.csv'), data, callback);
|
||||
});
|
||||
|
||||
this.Given(/^the data has been saved to disk$/, (callback) => {
|
||||
try {
|
||||
this.reprocess(callback);
|
||||
} catch(e) {
|
||||
this.processError = e;
|
||||
callback(e);
|
||||
}
|
||||
});
|
||||
|
||||
this.Given(/^the data has been extracted$/, (callback) => {
|
||||
this.writeAndExtract((err) => {
|
||||
if (err) this.processError = err;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.Given(/^the data has been contracted$/, (callback) => {
|
||||
this.reprocess((err) => {
|
||||
if (err) this.processError = err;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.Given(/^osrm\-routed is stopped$/, (callback) => {
|
||||
this.OSRMLoader.shutdown((err) => {
|
||||
if (err) this.processError = err;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.Given(/^data is loaded directly/, () => {
|
||||
this.loadMethod = 'directly';
|
||||
});
|
||||
|
||||
this.Given(/^data is loaded with datastore$/, () => {
|
||||
this.loadMethod = 'datastore';
|
||||
});
|
||||
|
||||
this.Given(/^the HTTP method "([^"]*)"$/, (method, callback) => {
|
||||
this.httpMethod = method;
|
||||
callback();
|
||||
});
|
||||
};
|
||||
@@ -1,202 +0,0 @@
|
||||
Given /^the profile "([^"]*)"$/ do |profile|
|
||||
set_profile profile
|
||||
end
|
||||
|
||||
Given(/^the import format "(.*?)"$/) do |format|
|
||||
set_input_format format
|
||||
end
|
||||
|
||||
Given /^the extract extra arguments "(.*?)"$/ do |args|
|
||||
set_extract_args args
|
||||
end
|
||||
|
||||
Given /^the contract extra arguments "(.*?)"$/ do |args|
|
||||
set_contract_args args
|
||||
end
|
||||
|
||||
Given /^a grid size of (\d+) meters$/ do |meters|
|
||||
set_grid_size meters
|
||||
end
|
||||
|
||||
Given /^the origin ([-+]?[0-9]*\.?[0-9]+),([-+]?[0-9]*\.?[0-9]+)$/ do |lat,lon|
|
||||
set_origin [lon.to_f,lat.to_f]
|
||||
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|
|
||||
unless name.empty?
|
||||
raise "*** node invalid name '#{name}', must be single characters" unless name.size == 1
|
||||
raise "*** invalid node name '#{name}', must me alphanumeric" unless name.match /[a-z0-9]/
|
||||
if name.match /[a-z]/
|
||||
raise "*** duplicate node '#{name}'" if name_node_hash[name]
|
||||
add_osm_node name, *table_coord_to_lonlat(ci,ri), nil
|
||||
else
|
||||
raise "*** duplicate node '#{name}'" if location_hash[name]
|
||||
add_location name, *table_coord_to_lonlat(ci,ri)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the node locations$/ do |table|
|
||||
table.hashes.each do |row|
|
||||
name = row['node']
|
||||
raise "*** duplicate node '#{name}'" if find_node_by_name name
|
||||
if name.match /[a-z]/
|
||||
id = row['id']
|
||||
id = id.to_i if id
|
||||
add_osm_node name, row['lon'].to_f, row['lat'].to_f, id
|
||||
else
|
||||
add_location name, row['lon'].to_f, row['lat'].to_f
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the nodes$/ do |table|
|
||||
table.hashes.each do |row|
|
||||
name = row.delete 'node'
|
||||
node = find_node_by_name(name)
|
||||
raise "*** unknown node '#{c}'" unless node
|
||||
node << row
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the ways$/ do |table|
|
||||
raise "*** Map data already defined - did you pass an input file in this scenaria?" if @osm_str
|
||||
table.hashes.each do |row|
|
||||
way = OSM::Way.new make_osm_id, OSM_USER, OSM_TIMESTAMP
|
||||
way.uid = OSM_UID
|
||||
|
||||
nodes = row.delete 'nodes'
|
||||
raise "*** duplicate way '#{nodes}'" if name_way_hash[nodes]
|
||||
nodes.each_char do |c|
|
||||
raise "*** ways can only use names a-z, '#{name}'" unless c.match /[a-z]/
|
||||
node = find_node_by_name(c)
|
||||
raise "*** unknown node '#{c}'" unless node
|
||||
way << node
|
||||
end
|
||||
|
||||
defaults = { 'highway' => 'primary' }
|
||||
tags = defaults.merge(row)
|
||||
|
||||
if row['highway'] == '(nil)'
|
||||
tags.delete 'highway'
|
||||
end
|
||||
|
||||
if row['name'] == nil
|
||||
tags['name'] = nodes
|
||||
elsif (row['name'] == '""') || (row['name'] == "''")
|
||||
tags['name'] = ''
|
||||
elsif row['name'] == '' || row['name'] == '(nil)'
|
||||
tags.delete 'name'
|
||||
else
|
||||
tags['name'] = row['name']
|
||||
end
|
||||
|
||||
way << tags
|
||||
osm_db << way
|
||||
name_way_hash[nodes] = way
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the relations$/ do |table|
|
||||
raise "*** Map data already defined - did you pass an input file in this scenaria?" if @osm_str
|
||||
table.hashes.each do |row|
|
||||
relation = OSM::Relation.new make_osm_id, OSM_USER, OSM_TIMESTAMP
|
||||
row.each_pair do |key,value|
|
||||
if key =~ /^node:(.*)/
|
||||
value.split(',').map { |v| v.strip }.each do |node_name|
|
||||
raise "***invalid relation node member '#{node_name}', must be single character" unless node_name.size == 1
|
||||
node = find_node_by_name(node_name)
|
||||
raise "*** unknown relation node member '#{node_name}'" unless node
|
||||
relation << OSM::Member.new( 'node', node.id, $1 )
|
||||
end
|
||||
elsif key =~ /^way:(.*)/
|
||||
value.split(',').map { |v| v.strip }.each do |way_name|
|
||||
way = find_way_by_name(way_name)
|
||||
raise "*** unknown relation way member '#{way_name}'" unless way
|
||||
relation << OSM::Member.new( 'way', way.id, $1 )
|
||||
end
|
||||
elsif key =~ /^(.*):(.*)/ && "#{$1}" != 'restriction'
|
||||
raise "*** unknown relation member type '#{$1}:#{$2}', must be either 'node' or 'way'"
|
||||
else
|
||||
relation << { key => value }
|
||||
end
|
||||
end
|
||||
relation.uid = OSM_UID
|
||||
osm_db << relation
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the defaults$/ do
|
||||
end
|
||||
|
||||
Given /^the input file ([^"]*)$/ do |file|
|
||||
raise "*** Input file must in .osm format" unless File.extname(file)=='.osm'
|
||||
@osm_str = File.read file
|
||||
end
|
||||
|
||||
Given /^the raster source$/ do |data|
|
||||
Dir.chdir TEST_FOLDER do
|
||||
File.open("rastersource.asc", "w") {|f| f.write(data)}
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the speed file$/ do |data|
|
||||
Dir.chdir TEST_FOLDER do
|
||||
File.open("speeds.csv", "w") {|f| f.write(data)}
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the data has been saved to disk$/ do
|
||||
begin
|
||||
write_input_data
|
||||
rescue OSRMError => e
|
||||
@process_error = e
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the data has been extracted$/ do
|
||||
begin
|
||||
write_input_data
|
||||
extract_data unless extracted?
|
||||
rescue OSRMError => e
|
||||
@process_error = e
|
||||
end
|
||||
end
|
||||
|
||||
Given /^the data has been contracted$/ do
|
||||
begin
|
||||
reprocess
|
||||
rescue OSRMError => e
|
||||
@process_error = e
|
||||
end
|
||||
end
|
||||
|
||||
Given /^osrm\-routed is stopped$/ do
|
||||
begin
|
||||
OSRMLoader.shutdown
|
||||
rescue OSRMError => e
|
||||
@process_error = e
|
||||
end
|
||||
end
|
||||
|
||||
Given /^data is loaded directly/ do
|
||||
@load_method = 'directly'
|
||||
end
|
||||
|
||||
Given /^data is loaded with datastore$/ do
|
||||
@load_method = 'datastore'
|
||||
end
|
||||
|
||||
Given /^the HTTP method "([^"]*)"$/ do |method|
|
||||
@http_method = method
|
||||
end
|
||||
@@ -0,0 +1,82 @@
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I request a travel time matrix I should get$/, (table, callback) => {
|
||||
var NO_ROUTE = 2147483647; // MAX_INT
|
||||
|
||||
var tableRows = table.raw();
|
||||
|
||||
if (tableRows[0][0] !== '') throw new Error('*** Top-left cell of matrix table must be empty');
|
||||
|
||||
var waypoints = [],
|
||||
columnHeaders = tableRows[0].slice(1),
|
||||
rowHeaders = tableRows.map((h) => h[0]).slice(1),
|
||||
symmetric = columnHeaders.every((ele, i) => ele === rowHeaders[i]);
|
||||
|
||||
if (symmetric) {
|
||||
columnHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"'), nodeName);
|
||||
waypoints.push({ coord: node, type: 'loc' });
|
||||
});
|
||||
} else {
|
||||
columnHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"'), nodeName);
|
||||
waypoints.push({ coord: node, type: 'dst' });
|
||||
});
|
||||
rowHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"'), nodeName);
|
||||
waypoints.push({ coord: node, type: 'src' });
|
||||
});
|
||||
}
|
||||
|
||||
var actual = [];
|
||||
actual.push(table.headers);
|
||||
|
||||
this.reprocessAndLoadData(() => {
|
||||
// compute matrix
|
||||
var params = this.queryParams;
|
||||
|
||||
this.requestTable(waypoints, params, (err, response) => {
|
||||
if (err) return callback(err);
|
||||
if (!response.body.length) return callback(new Error('Invalid response body'));
|
||||
|
||||
var jsonResult = JSON.parse(response.body),
|
||||
result = jsonResult['distance_table'].map((row) => {
|
||||
var hashes = {};
|
||||
row.forEach((c, j) => {
|
||||
hashes[tableRows[0][j+1]] = c;
|
||||
});
|
||||
return hashes;
|
||||
});
|
||||
|
||||
var testRow = (row, ri, cb) => {
|
||||
var ok = true;
|
||||
|
||||
for (var k in result[ri]) {
|
||||
if (this.FuzzyMatch.match(result[ri][k], row[k])) {
|
||||
result[ri][k] = row[k];
|
||||
} else if (row[k] === '' && result[ri][k] === NO_ROUTE) {
|
||||
result[ri][k] = '';
|
||||
} else {
|
||||
result[ri][k] = result[ri][k].toString();
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
var failed = { attempt: 'distance_matrix', query: this.query, response: response };
|
||||
this.logFail(row, result[ri], [failed]);
|
||||
}
|
||||
|
||||
result[ri][''] = row[''];
|
||||
cb(null, result[ri]);
|
||||
};
|
||||
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,66 +0,0 @@
|
||||
When /^I request a travel time matrix I should get$/ do |table|
|
||||
no_route = 2147483647 # MAX_INT
|
||||
|
||||
raise "*** Top-left cell of matrix table must be empty" unless table.headers[0]==""
|
||||
|
||||
waypoints = []
|
||||
column_headers = table.headers[1..-1]
|
||||
row_headers = table.rows.map { |h| h.first }
|
||||
symmetric = Set.new(column_headers) == Set.new(row_headers)
|
||||
if symmetric then
|
||||
column_headers.each do |node_name|
|
||||
node = find_node_by_name(node_name)
|
||||
raise "*** unknown node '#{node_name}" unless node
|
||||
waypoints << {:coord => node, :type => "loc"}
|
||||
end
|
||||
else
|
||||
column_headers.each do |node_name|
|
||||
node = find_node_by_name(node_name)
|
||||
raise "*** unknown node '#{node_name}" unless node
|
||||
waypoints << {:coord => node, :type => "dst"}
|
||||
end
|
||||
row_headers.each do |node_name|
|
||||
node = find_node_by_name(node_name)
|
||||
raise "*** unknown node '#{node_name}" unless node
|
||||
waypoints << {:coord => node, :type => "src"}
|
||||
end
|
||||
end
|
||||
|
||||
reprocess
|
||||
actual = []
|
||||
actual << table.headers
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") do
|
||||
|
||||
# compute matrix
|
||||
params = @query_params
|
||||
response = request_table waypoints, params
|
||||
if response.body.empty? == false
|
||||
json_result = JSON.parse response.body
|
||||
result = json_result["distance_table"]
|
||||
end
|
||||
|
||||
|
||||
# compare actual and expected result, one row at a time
|
||||
table.rows.each_with_index do |row,ri|
|
||||
# fuzzy match
|
||||
ok = true
|
||||
0.upto(result[ri].size-1) do |i|
|
||||
if FuzzyMatch.match result[ri][i], row[i+1]
|
||||
result[ri][i] = row[i+1]
|
||||
elsif row[i+1]=="" and result[ri][i]==no_route
|
||||
result[ri][i] = ""
|
||||
else
|
||||
result[ri][i] = result[ri][i].to_s
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
|
||||
# add row header
|
||||
r = [row[0],result[ri]].flatten
|
||||
|
||||
# store row for comparison
|
||||
actual << r
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function () {
|
||||
this.Before((scenario, callback) => {
|
||||
this.scenarioTitle = scenario.getName();
|
||||
|
||||
this.loadMethod = this.DEFAULT_LOAD_METHOD;
|
||||
this.queryParams = [];
|
||||
var d = new Date();
|
||||
this.scenarioTime = util.format('%d-%d-%dT%s:%s:%sZ', d.getFullYear(), d.getMonth()+1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds());
|
||||
this.resetData();
|
||||
this.hasLoggedPreprocessInfo = false;
|
||||
this.hasLoggedScenarioInfo = false;
|
||||
this.setGridSize(this.DEFAULT_GRID_SIZE);
|
||||
this.setOrigin(this.DEFAULT_ORIGIN);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Before('@ignore-platform-windows', () => {
|
||||
this.skipThisScenario();
|
||||
});
|
||||
|
||||
this.Before('@ignore-platform-unix', () => {
|
||||
this.skipThisScenario();
|
||||
});
|
||||
|
||||
this.Before('@ignore-platform-mac', () => {
|
||||
this.skipThisScenario();
|
||||
});
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
Before '@ignore-platform-windows' do
|
||||
skip_this_scenario
|
||||
end
|
||||
|
||||
Before '@ignore-platform-unix' do
|
||||
skip_this_scenario
|
||||
end
|
||||
|
||||
Before '@ignore-platform-mac' do
|
||||
skip_this_scenario
|
||||
end
|
||||
@@ -0,0 +1,174 @@
|
||||
var util = require('util');
|
||||
var d3 = require('d3-queue');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I match I should get$/, (table, callback) => {
|
||||
var got;
|
||||
|
||||
this.reprocessAndLoadData(() => {
|
||||
var testRow = (row, ri, cb) => {
|
||||
var afterRequest = (err, res) => {
|
||||
if (err) return cb(err);
|
||||
var json;
|
||||
|
||||
var headers = new Set(table.raw()[0]);
|
||||
|
||||
if (res.body.length) {
|
||||
json = JSON.parse(res.body);
|
||||
}
|
||||
|
||||
if (headers.has('status')) {
|
||||
got.status = json.status.toString();
|
||||
}
|
||||
|
||||
if (headers.has('message')) {
|
||||
got.message = json.status_message;
|
||||
}
|
||||
|
||||
if (headers.has('#')) {
|
||||
// comment column
|
||||
got['#'] = row['#'];
|
||||
}
|
||||
|
||||
var subMatchings = [],
|
||||
turns = '',
|
||||
route = '',
|
||||
duration = '';
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
if (headers.has('matchings')) {
|
||||
subMatchings = json.matchings.filter(m => !!m).map(sub => sub.matched_points);
|
||||
}
|
||||
|
||||
if (headers.has('turns')) {
|
||||
if (json.matchings.length != 1) throw new Error('*** Checking turns only supported for matchings with one subtrace');
|
||||
turns = this.turnList(json.matchings[0].instructions);
|
||||
}
|
||||
|
||||
if (headers.has('route')) {
|
||||
if (json.matchings.length != 1) throw new Error('*** Checking route only supported for matchings with one subtrace');
|
||||
route = this.wayList(json.matchings[0].instructions);
|
||||
}
|
||||
|
||||
if (headers.has('duration')) {
|
||||
if (json.matchings.length != 1) throw new Error('*** Checking duration only supported for matchings with one subtrace');
|
||||
duration = json.matchings[0].route_summary.total_time;
|
||||
}
|
||||
}
|
||||
|
||||
if (headers.has('turns')) {
|
||||
got.turns = turns;
|
||||
}
|
||||
|
||||
if (headers.has('route')) {
|
||||
got.route = route;
|
||||
}
|
||||
|
||||
if (headers.has('duration')) {
|
||||
got.duration = duration.toString();
|
||||
}
|
||||
|
||||
var ok = true;
|
||||
var encodedResult = '',
|
||||
extendedTarget = '';
|
||||
|
||||
var q = d3.queue();
|
||||
|
||||
var testSubMatching = (sub, si, scb) => {
|
||||
if (si >= subMatchings.length) {
|
||||
ok = false;
|
||||
q.abort();
|
||||
scb();
|
||||
} else {
|
||||
var sq = d3.queue();
|
||||
|
||||
var testSubNode = (ni, ncb) => {
|
||||
var node = this.findNodeByName(sub[ni]),
|
||||
outNode = subMatchings[si][ni];
|
||||
|
||||
if (this.FuzzyMatch.matchLocation(outNode, node)) {
|
||||
encodedResult += sub[ni];
|
||||
extendedTarget += sub[ni];
|
||||
} else {
|
||||
encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]);
|
||||
extendedTarget += util.format('%s [%d,%d]', node.lat, node.lon);
|
||||
ok = false;
|
||||
}
|
||||
ncb();
|
||||
};
|
||||
|
||||
for (var i=0; i<sub.length; i++) {
|
||||
sq.defer(testSubNode, i);
|
||||
}
|
||||
|
||||
sq.awaitAll(scb);
|
||||
}
|
||||
};
|
||||
|
||||
row.matchings.split(',').forEach((sub, si) => {
|
||||
q.defer(testSubMatching, sub, si);
|
||||
});
|
||||
|
||||
q.awaitAll(() => {
|
||||
if (ok) {
|
||||
if (headers.has('matchings')) {
|
||||
got.matchings = row.matchings;
|
||||
}
|
||||
|
||||
if (headers.has('timestamps')) {
|
||||
got.timestamps = row.timestamps;
|
||||
}
|
||||
} else {
|
||||
got.matchings = encodedResult;
|
||||
row.matchings = extendedTarget;
|
||||
this.logFail(row, got, { matching: { query: this.query, response: res } });
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
});
|
||||
};
|
||||
|
||||
if (row.request) {
|
||||
got = {};
|
||||
got.request = row.request;
|
||||
this.requestUrl(row.request, afterRequest);
|
||||
} else {
|
||||
var params = this.queryParams;
|
||||
got = {};
|
||||
for (var k in row) {
|
||||
var match = k.match(/param:(.*)/);
|
||||
if (match) {
|
||||
if (row[k] === '(nil)') {
|
||||
params[match[1]] = null;
|
||||
} else if (row[k]) {
|
||||
params[match[1]] = [row[k]];
|
||||
}
|
||||
got[k] = row[k];
|
||||
}
|
||||
}
|
||||
|
||||
var trace = [],
|
||||
timestamps = [];
|
||||
|
||||
if (row.trace) {
|
||||
for (var i=0; i<row.trace.length; i++) {
|
||||
var n = row.trace[i],
|
||||
node = this.findNodeByName(n);
|
||||
if (!node) throw new Error(util.format('*** unknown waypoint node "%s"'), n);
|
||||
trace.push(node);
|
||||
}
|
||||
if (row.timestamps) {
|
||||
timestamps = row.timestamps.split(' ').filter(s => !!s).map(t => parseInt(t));
|
||||
}
|
||||
got.trace = row.trace;
|
||||
this.requestMatching(trace, timestamps, params, afterRequest);
|
||||
} else {
|
||||
throw new Error('*** no trace');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,124 +0,0 @@
|
||||
When /^I match I should get$/ do |table|
|
||||
reprocess
|
||||
actual = []
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,ri|
|
||||
if row['request']
|
||||
got = {'request' => row['request'] }
|
||||
response = request_url row['request']
|
||||
else
|
||||
params = @query_params
|
||||
got = {}
|
||||
row.each_pair do |k,v|
|
||||
if k =~ /param:(.*)/
|
||||
if v=='(nil)'
|
||||
params[$1]=nil
|
||||
elsif v!=nil
|
||||
params[$1]=[v]
|
||||
end
|
||||
got[k]=v
|
||||
end
|
||||
end
|
||||
trace = []
|
||||
timestamps = []
|
||||
if row['trace']
|
||||
row['trace'].each_char do |n|
|
||||
node = find_node_by_name(n.strip)
|
||||
raise "*** unknown waypoint node '#{n.strip}" unless node
|
||||
trace << node
|
||||
end
|
||||
if row['timestamps']
|
||||
timestamps = row['timestamps'].split(" ").compact.map { |t| t.to_i}
|
||||
end
|
||||
got = got.merge({'trace' => row['trace'] })
|
||||
response = request_matching trace, timestamps, params
|
||||
else
|
||||
raise "*** no trace"
|
||||
end
|
||||
end
|
||||
|
||||
if response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
end
|
||||
|
||||
if table.headers.include? 'status'
|
||||
got['status'] = json['status'].to_s
|
||||
end
|
||||
if table.headers.include? 'message'
|
||||
got['message'] = json['status_message']
|
||||
end
|
||||
if table.headers.include? '#' # comment column
|
||||
got['#'] = row['#'] # copy value so it always match
|
||||
end
|
||||
|
||||
sub_matchings = []
|
||||
turns = ''
|
||||
route = ''
|
||||
duration = ''
|
||||
if response.code == "200"
|
||||
if table.headers.include? 'matchings'
|
||||
sub_matchings = json['matchings'].compact.map { |sub| sub['matched_points']}
|
||||
end
|
||||
if table.headers.include? 'turns'
|
||||
raise "*** Checking turns only support for matchings with one subtrace" unless json['matchings'].size == 1
|
||||
turns = turn_list json['matchings'][0]['instructions']
|
||||
end
|
||||
if table.headers.include? 'route'
|
||||
raise "*** Checking route only support for matchings with one subtrace" unless json['matchings'].size == 1
|
||||
route = way_list json['matchings'][0]['instructions']
|
||||
if table.headers.include? 'duration'
|
||||
raise "*** Checking duration only support for matchings with one subtrace" unless json['matchings'].size == 1
|
||||
duration = json['matchings'][0]['route_summary']['total_time']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if table.headers.include? 'turns'
|
||||
got['turns'] = turns
|
||||
end
|
||||
if table.headers.include? 'route'
|
||||
got['route'] = route
|
||||
end
|
||||
if table.headers.include? 'duration'
|
||||
got['duration'] = duration.to_s
|
||||
end
|
||||
|
||||
ok = true
|
||||
encoded_result = ""
|
||||
extended_target = ""
|
||||
row['matchings'].split(',').each_with_index do |sub, sub_idx|
|
||||
if sub_idx >= sub_matchings.length
|
||||
ok = false
|
||||
break
|
||||
end
|
||||
sub.length.times do |node_idx|
|
||||
node = find_node_by_name(sub[node_idx])
|
||||
out_node = sub_matchings[sub_idx][node_idx]
|
||||
if FuzzyMatch.match_location out_node, node
|
||||
encoded_result += sub[node_idx]
|
||||
extended_target += sub[node_idx]
|
||||
else
|
||||
encoded_result += "? [#{out_node[0]},#{out_node[1]}]"
|
||||
extended_target += "#{sub[node_idx]} [#{node.lat},#{node.lon}]"
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
end
|
||||
if ok
|
||||
if table.headers.include? 'matchings'
|
||||
got['matchings'] = row['matchings']
|
||||
end
|
||||
if table.headers.include? 'timestamps'
|
||||
got['timestamps'] = row['timestamps']
|
||||
end
|
||||
else
|
||||
got['matchings'] = encoded_result
|
||||
row['matchings'] = extended_target
|
||||
log_fail row,got, { 'matching' => {:query => @query, :response => response} }
|
||||
end
|
||||
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I request nearest I should get$/, (table, callback) => {
|
||||
this.reprocessAndLoadData(() => {
|
||||
var testRow = (row, ri, cb) => {
|
||||
var inNode = this.findNodeByName(row.in);
|
||||
if (!inNode) throw new Error(util.format('*** unknown in-node "%s"'), row.in);
|
||||
|
||||
var outNode = this.findNodeByName(row.out);
|
||||
if (!outNode) throw new Error(util.format('*** unknown out-node "%s"'), row.out);
|
||||
|
||||
this.requestNearest(inNode, this.queryParams, (err, response) => {
|
||||
if (err) return cb(err);
|
||||
var coord;
|
||||
|
||||
if (response.statusCode === 200 && response.body.length) {
|
||||
var json = JSON.parse(response.body);
|
||||
|
||||
coord = json.mapped_coordinate;
|
||||
|
||||
var got = { in: row.in, out: row.out };
|
||||
|
||||
var ok = true;
|
||||
|
||||
Object.keys(row).forEach((key) => {
|
||||
if (key === 'out') {
|
||||
if (this.FuzzyMatch.matchLocation(coord, outNode)) {
|
||||
got[key] = row[key];
|
||||
} else {
|
||||
row[key] = util.format('%s [%d,%d]', row[key], outNode.lat, outNode.lon);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!ok) {
|
||||
var failed = { attempt: 'nearest', query: this.query, response: response };
|
||||
this.logFail(row, got, [failed]);
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
}
|
||||
else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,51 +0,0 @@
|
||||
When /^I request nearest I should get$/ do |table|
|
||||
reprocess
|
||||
actual = []
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") 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_nearest in_node, @query_params
|
||||
if response.code == "200" && response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
if json['status'] == 200
|
||||
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 => 'nearest', :query => @query, :response => response }
|
||||
log_fail row,got,[failed]
|
||||
end
|
||||
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
|
||||
When /^I request nearest (\d+) times I should get$/ do |n,table|
|
||||
ok = true
|
||||
n.to_i.times do
|
||||
ok = false unless step "I request nearest I should get", table
|
||||
end
|
||||
ok
|
||||
end
|
||||
@@ -0,0 +1,69 @@
|
||||
var assert = require('assert');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I run "osrm\-routed\s?(.*?)"$/, { timeout: this.SHUTDOWN_TIMEOUT }, (options, callback) => {
|
||||
this.runBin('osrm-routed', options, () => {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.When(/^I run "osrm\-extract\s?(.*?)"$/, (options, callback) => {
|
||||
this.runBin('osrm-extract', options, () => {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.When(/^I run "osrm\-contract\s?(.*?)"$/, (options, callback) => {
|
||||
this.runBin('osrm-contract', options, () => {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.When(/^I run "osrm\-datastore\s?(.*?)"$/, (options, callback) => {
|
||||
this.runBin('osrm-datastore', options, () => {
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
this.Then(/^it should exit with code (\d+)$/, (code) => {
|
||||
assert.equal(this.exitCode, parseInt(code));
|
||||
});
|
||||
|
||||
this.Then(/^stdout should contain "(.*?)"$/, (str) => {
|
||||
assert.ok(this.stdout.indexOf(str) > -1);
|
||||
});
|
||||
|
||||
this.Then(/^stderr should contain "(.*?)"$/, (str) => {
|
||||
assert.ok(this.stderr.indexOf(str) > -1);
|
||||
});
|
||||
|
||||
this.Then(/^stdout should contain \/(.*)\/$/, (regexStr) => {
|
||||
var re = new RegExp(regexStr);
|
||||
assert.ok(this.stdout.match(re));
|
||||
});
|
||||
|
||||
this.Then(/^stderr should contain \/(.*)\/$/, (regexStr) => {
|
||||
var re = new RegExp(regexStr);
|
||||
assert.ok(this.stdout.match(re));
|
||||
});
|
||||
|
||||
this.Then(/^stdout should be empty$/, () => {
|
||||
assert.equal(this.stdout.trim(), '');
|
||||
});
|
||||
|
||||
this.Then(/^stderr should be empty$/, () => {
|
||||
assert.equal(this.stderr.trim(), '');
|
||||
});
|
||||
|
||||
this.Then(/^stdout should contain (\d+) lines?$/, (lines) => {
|
||||
assert.equal(this.stdout.split('\n').length - 1, parseInt(lines));
|
||||
});
|
||||
|
||||
this.Given(/^the query options$/, (table, callback) => {
|
||||
table.raw().forEach((tuple) => {
|
||||
this.queryParams.push(tuple);
|
||||
});
|
||||
|
||||
callback();
|
||||
});
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
When(/^I run "osrm\-routed\s?(.*?)"$/) do |options|
|
||||
begin
|
||||
Timeout.timeout(SHUTDOWN_TIMEOUT) { run_bin 'osrm-routed', options }
|
||||
rescue Timeout::Error
|
||||
raise "*** osrm-routed didn't quit. Maybe the --trial option wasn't used?"
|
||||
end
|
||||
end
|
||||
|
||||
When(/^I run "osrm\-extract\s?(.*?)"$/) do |options|
|
||||
run_bin 'osrm-extract', options
|
||||
end
|
||||
|
||||
When(/^I run "osrm\-contract\s?(.*?)"$/) do |options|
|
||||
run_bin 'osrm-contract', options
|
||||
end
|
||||
|
||||
When(/^I run "osrm\-datastore\s?(.*?)"$/) do |options|
|
||||
run_bin 'osrm-datastore', options
|
||||
end
|
||||
|
||||
Then /^it should exit with code (\d+)$/ do |code|
|
||||
expect(@exit_code).to eq( code.to_i )
|
||||
end
|
||||
|
||||
Then /^stdout should contain "(.*?)"$/ do |str|
|
||||
expect(@stdout).to include(str)
|
||||
end
|
||||
|
||||
Then /^stderr should contain "(.*?)"$/ do |str|
|
||||
expect(@stderr).to include(str)
|
||||
end
|
||||
|
||||
Then(/^stdout should contain \/(.*)\/$/) do |regex_str|
|
||||
regex = Regexp.new regex_str
|
||||
expect(@stdout).to match( regex )
|
||||
end
|
||||
|
||||
Then(/^stderr should contain \/(.*)\/$/) do |regex_str|
|
||||
regex = Regexp.new regex_str
|
||||
expect(@stderr).to match( regex )
|
||||
end
|
||||
|
||||
Then /^stdout should be empty$/ do
|
||||
expect(@stdout).to eq("")
|
||||
end
|
||||
|
||||
Then /^stderr should be empty$/ do
|
||||
expect(@stderr).to eq("")
|
||||
end
|
||||
|
||||
Then /^stdout should contain (\d+) lines?$/ do |lines|
|
||||
expect(@stdout.lines.count).to eq( lines.to_i )
|
||||
end
|
||||
|
||||
Given (/^the query options$/) do |table|
|
||||
table.rows_hash.each { |k,v| @query_params << [k, v] }
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
var assert = require('assert');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I request \/(.*)$/, (path, callback) => {
|
||||
this.reprocessAndLoadData(() => {
|
||||
this.requestPath(path, [], (err, res, body) => {
|
||||
this.response = res;
|
||||
callback(err, res, body);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
this.Then(/^I should get a response/, () => {
|
||||
this.ShouldGetAResponse();
|
||||
});
|
||||
|
||||
this.Then(/^response should be valid JSON$/, (callback) => {
|
||||
this.ShouldBeValidJSON(callback);
|
||||
});
|
||||
|
||||
this.Then(/^response should be well-formed$/, () => {
|
||||
this.ShouldBeWellFormed();
|
||||
});
|
||||
|
||||
this.Then(/^status code should be (\d+)$/, (code, callback) => {
|
||||
try {
|
||||
this.json = JSON.parse(this.response.body);
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
assert.equal(this.json.status, parseInt(code));
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Then(/^status message should be "(.*?)"$/, (message, callback) => {
|
||||
try {
|
||||
this.json = JSON.parse(this.response.body);
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
assert(this.json.status_message, message);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Then(/^response should be a well-formed route$/, () => {
|
||||
this.ShouldBeWellFormed();
|
||||
assert.equal(typeof this.json.status_message, 'string');
|
||||
assert.equal(typeof this.json.route_summary, 'object');
|
||||
assert.equal(typeof this.json.route_geometry, 'string');
|
||||
assert.ok(Array.isArray(this.json.route_instructions));
|
||||
assert.ok(Array.isArray(this.json.via_points));
|
||||
assert.ok(Array.isArray(this.json.via_indices));
|
||||
});
|
||||
|
||||
this.Then(/^"([^"]*)" should return code (\d+)$/, (binary, code) => {
|
||||
assert.ok(this.processError instanceof this.OSRMError);
|
||||
assert.equal(this.processError.process, binary);
|
||||
assert.equal(parseInt(this.processError.code), parseInt(code));
|
||||
});
|
||||
};
|
||||
@@ -1,46 +0,0 @@
|
||||
When /^I request \/(.*)$/ do |path|
|
||||
reprocess
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") do
|
||||
@response = request_path path, []
|
||||
end
|
||||
end
|
||||
|
||||
Then /^I should get a response/ do
|
||||
expect(@response.code).to eq("200")
|
||||
expect(@response.body).not_to eq(nil)
|
||||
expect(@response.body).not_to eq('')
|
||||
end
|
||||
|
||||
Then /^response should be valid JSON$/ do
|
||||
@json = JSON.parse @response.body
|
||||
end
|
||||
|
||||
Then /^response should be well-formed$/ do
|
||||
expect(@json['status'].class).to eq(Fixnum)
|
||||
end
|
||||
|
||||
Then /^status code should be (\d+)$/ do |code|
|
||||
@json = JSON.parse @response.body
|
||||
expect(@json['status']).to eq(code.to_i)
|
||||
end
|
||||
|
||||
Then /^status message should be "(.*?)"$/ do |message|
|
||||
@json = JSON.parse @response.body
|
||||
expect(@json['status_message']).to eq(message)
|
||||
end
|
||||
|
||||
Then /^response should be a well-formed route$/ do
|
||||
step "response should be well-formed"
|
||||
expect(@json['status_message'].class).to eq(String)
|
||||
expect(@json['route_summary'].class).to eq(Hash)
|
||||
expect(@json['route_geometry'].class).to eq(String)
|
||||
expect(@json['route_instructions'].class).to eq(Array)
|
||||
expect(@json['via_points'].class).to eq(Array)
|
||||
expect(@json['via_indices'].class).to eq(Array)
|
||||
end
|
||||
|
||||
Then /^"([^"]*)" should return code (\d+)$/ do |binary, code|
|
||||
expect(@process_error.is_a?(OSRMError)).to eq(true)
|
||||
expect(@process_error.process).to eq(binary)
|
||||
expect(@process_error.code.to_i).to eq(code.to_i)
|
||||
end
|
||||
@@ -0,0 +1,110 @@
|
||||
var util = require('util');
|
||||
var d3 = require('d3-queue');
|
||||
var classes = require('../support/data_classes');
|
||||
|
||||
module.exports = function () {
|
||||
this.Then(/^routability should be$/, (table, callback) => {
|
||||
this.buildWaysFromTable(table, () => {
|
||||
var directions = ['forw','backw','bothw'];
|
||||
|
||||
if (!directions.some(k => !!table.hashes()[0].hasOwnProperty(k))) {
|
||||
throw new Error('*** routability table must contain either "forw", "backw" or "bothw" column');
|
||||
}
|
||||
this.reprocessAndLoadData(() => {
|
||||
var testRow = (row, i, cb) => {
|
||||
var outputRow = row;
|
||||
|
||||
testRoutabilityRow(i, (err, result) => {
|
||||
if (err) return cb(err);
|
||||
directions.filter(d => !!table.hashes()[0][d]).forEach((direction) => {
|
||||
var want = this.shortcutsHash[row[direction]] || row[direction];
|
||||
|
||||
switch (true) {
|
||||
case '' === want:
|
||||
case 'x' === want:
|
||||
outputRow[direction] = result[direction].status ?
|
||||
result[direction].status.toString() : '';
|
||||
break;
|
||||
case /^\d+s/.test(want):
|
||||
break;
|
||||
case /^\d+ km\/h/.test(want):
|
||||
break;
|
||||
default:
|
||||
throw new Error(util.format('*** Unknown expectation format: %s', want));
|
||||
}
|
||||
|
||||
if (this.FuzzyMatch.match(outputRow[direction], want)) {
|
||||
outputRow[direction] = row[direction];
|
||||
}
|
||||
});
|
||||
|
||||
if (outputRow != row) {
|
||||
this.logFail(row, outputRow, result);
|
||||
}
|
||||
|
||||
cb(null, outputRow);
|
||||
});
|
||||
};
|
||||
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var testRoutabilityRow = (i, cb) => {
|
||||
var result = {};
|
||||
|
||||
var testDirection = (dir, callback) => {
|
||||
var a = new classes.Location(this.origin[0] + (1+this.WAY_SPACING*i) * this.zoom, this.origin[1]),
|
||||
b = new classes.Location(this.origin[0] + (3+this.WAY_SPACING*i) * this.zoom, this.origin[1]),
|
||||
r = {};
|
||||
|
||||
r.which = dir;
|
||||
|
||||
this.requestRoute((dir === 'forw' ? [a, b] : [b, a]), [], this.queryParams, (err, res, body) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
r.query = this.query;
|
||||
r.json = JSON.parse(body);
|
||||
r.status = r.json.status === 200 ? 'x' : null;
|
||||
if (r.status) {
|
||||
r.route = this.wayList(r.json.route_instructions);
|
||||
|
||||
if (r.route === util.format('w%d', i)) {
|
||||
r.time = r.json.route_summary.total_time;
|
||||
r.distance = r.json.route_summary.total_distance;
|
||||
r.speed = r.time > 0 ? parseInt(3.6 * r.distance / r.time) : null;
|
||||
} else {
|
||||
r.status = null;
|
||||
}
|
||||
}
|
||||
|
||||
callback(null, r);
|
||||
});
|
||||
};
|
||||
|
||||
d3.queue()
|
||||
.defer(testDirection, 'forw')
|
||||
.defer(testDirection, 'backw')
|
||||
.awaitAll((err, res) => {
|
||||
if (err) return cb(err);
|
||||
// check if forw and backw returned the same values
|
||||
res.forEach((dirRes) => {
|
||||
var which = dirRes.which;
|
||||
delete dirRes.which;
|
||||
result[which] = dirRes;
|
||||
});
|
||||
|
||||
result.bothw = {};
|
||||
['status', 'time', 'distance', 'speed'].forEach((key) => {
|
||||
if (result.forw[key] === result.backw[key]) {
|
||||
result.bothw[key] = result.forw[key];
|
||||
} else {
|
||||
result.bothw[key] = 'diff';
|
||||
}
|
||||
});
|
||||
|
||||
cb(null, result);
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -1,78 +0,0 @@
|
||||
def test_routability_row i
|
||||
result = {}
|
||||
['forw','backw'].each do |direction|
|
||||
a = Location.new @origin[0]+(1+WAY_SPACING*i)*@zoom, @origin[1]
|
||||
b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
|
||||
r = {}
|
||||
r[:response] = request_route (direction=='forw' ? [a,b] : [b,a]), [], @query_params
|
||||
r[:query] = @query
|
||||
r[:json] = JSON.parse(r[:response].body)
|
||||
|
||||
r[:status] = (route_status r[:response]) == 200 ? 'x' : nil
|
||||
if r[:status] then
|
||||
r[:route] = way_list r[:json]['route_instructions']
|
||||
|
||||
if r[:route]=="w#{i}"
|
||||
r[:time] = r[:json]['route_summary']['total_time']
|
||||
r[:distance] = r[:json]['route_summary']['total_distance']
|
||||
r[:speed] = r[:time]>0 ? (3.6*r[:distance]/r[:time]).to_i : nil
|
||||
else
|
||||
# if we hit the wrong way segment, we assume it's
|
||||
# because the one we tested was not unroutable
|
||||
r[:status] = nil
|
||||
end
|
||||
end
|
||||
result[direction] = r
|
||||
end
|
||||
|
||||
# check if forw and backw returned the same values
|
||||
result['bothw'] = {}
|
||||
[:status,:time,:distance,:speed].each do |key|
|
||||
if result['forw'][key] == result['backw'][key]
|
||||
result['bothw'][key] = result['forw'][key]
|
||||
else
|
||||
result['bothw'][key] = 'diff'
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
Then /^routability should be$/ do |table|
|
||||
build_ways_from_table table
|
||||
reprocess
|
||||
actual = []
|
||||
if table.headers&["forw","backw","bothw"] == []
|
||||
raise "*** routability tabel must contain either 'forw', 'backw' or 'bothw' column"
|
||||
end
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,i|
|
||||
output_row = row.dup
|
||||
attempts = []
|
||||
result = test_routability_row i
|
||||
directions = ['forw','backw','bothw']
|
||||
(directions & table.headers).each do |direction|
|
||||
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
|
||||
case want
|
||||
when '', 'x'
|
||||
output_row[direction] = result[direction][:status] ? result[direction][:status].to_s : ''
|
||||
when /^\d+s/
|
||||
output_row[direction] = result[direction][:time] ? "#{result[direction][:time]}s" : ''
|
||||
when /^\d+ km\/h/
|
||||
output_row[direction] = result[direction][:speed] ? "#{result[direction][:speed]} km/h" : ''
|
||||
else
|
||||
raise "*** Unknown expectation format: #{want}"
|
||||
end
|
||||
|
||||
if FuzzyMatch.match output_row[direction], want
|
||||
output_row[direction] = row[direction]
|
||||
end
|
||||
end
|
||||
|
||||
if output_row != row
|
||||
log_fail row,output_row,result
|
||||
end
|
||||
actual << output_row
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
var d3 = require('d3-queue');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I route I should get$/, this.WhenIRouteIShouldGet);
|
||||
|
||||
// This is used to route 100 times; timeout for entire step is therefore set to 100 * STRESS_TIMEOUT
|
||||
this.When(/^I route (\d+) times I should get$/, { timeout: 30000 }, (n, table, callback) => {
|
||||
var q = d3.queue(1);
|
||||
|
||||
for (var i=0; i<n; i++) {
|
||||
q.defer(this.WhenIRouteIShouldGet, table);
|
||||
}
|
||||
|
||||
q.awaitAll(callback);
|
||||
});
|
||||
};
|
||||
@@ -1,165 +0,0 @@
|
||||
When /^I route I should get$/ do |table|
|
||||
reprocess
|
||||
actual = []
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,ri|
|
||||
if row['request']
|
||||
got = {'request' => row['request'] }
|
||||
response = request_url row['request']
|
||||
else
|
||||
default_params = @query_params
|
||||
user_params = []
|
||||
got = {}
|
||||
row.each_pair do |k,v|
|
||||
if k =~ /param:(.*)/
|
||||
if v=='(nil)'
|
||||
user_params << [$1, nil]
|
||||
elsif v!=nil
|
||||
user_params << [$1, v]
|
||||
end
|
||||
got[k]=v
|
||||
end
|
||||
end
|
||||
params = overwrite_params default_params, user_params
|
||||
waypoints = []
|
||||
bearings = []
|
||||
if row['bearings']
|
||||
got['bearings'] = row['bearings']
|
||||
bearings = row['bearings'].split(' ').compact
|
||||
end
|
||||
if row['from'] and row['to']
|
||||
node = find_node_by_name(row['from'])
|
||||
raise "*** unknown from-node '#{row['from']}" unless node
|
||||
waypoints << node
|
||||
|
||||
node = find_node_by_name(row['to'])
|
||||
raise "*** unknown to-node '#{row['to']}" unless node
|
||||
waypoints << node
|
||||
|
||||
got = got.merge({'from' => row['from'], 'to' => row['to'] })
|
||||
response = request_route waypoints, bearings, params
|
||||
elsif row['waypoints']
|
||||
row['waypoints'].split(',').each do |n|
|
||||
node = find_node_by_name(n.strip)
|
||||
raise "*** unknown waypoint node '#{n.strip}" unless node
|
||||
waypoints << node
|
||||
end
|
||||
got = got.merge({'waypoints' => row['waypoints'] })
|
||||
response = request_route waypoints, bearings, params
|
||||
else
|
||||
raise "*** no waypoints"
|
||||
end
|
||||
end
|
||||
|
||||
if response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
end
|
||||
|
||||
if response.body.empty? == false
|
||||
if json['status'] == 200
|
||||
instructions = way_list json['route_instructions']
|
||||
bearings = bearing_list json['route_instructions']
|
||||
compasses = compass_list json['route_instructions']
|
||||
turns = turn_list json['route_instructions']
|
||||
modes = mode_list json['route_instructions']
|
||||
times = time_list json['route_instructions']
|
||||
distances = distance_list json['route_instructions']
|
||||
end
|
||||
end
|
||||
|
||||
if table.headers.include? 'status'
|
||||
got['status'] = json['status'].to_s
|
||||
end
|
||||
if table.headers.include? 'message'
|
||||
got['message'] = json['status_message']
|
||||
end
|
||||
if table.headers.include? '#' # comment column
|
||||
got['#'] = row['#'] # copy value so it always match
|
||||
end
|
||||
|
||||
if table.headers.include? 'start'
|
||||
got['start'] = instructions ? json['route_summary']['start_point'] : nil
|
||||
end
|
||||
if table.headers.include? 'end'
|
||||
got['end'] = instructions ? json['route_summary']['end_point'] : nil
|
||||
end
|
||||
if table.headers.include? 'geometry'
|
||||
got['geometry'] = json['route_geometry']
|
||||
end
|
||||
if table.headers.include? 'route'
|
||||
got['route'] = (instructions || '').strip
|
||||
if table.headers.include?('alternative')
|
||||
got['alternative'] =
|
||||
if json['found_alternative']
|
||||
way_list json['alternative_instructions'].first
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
if table.headers.include?('distance')
|
||||
if row['distance']!=''
|
||||
raise "*** Distance must be specied in meters. (ex: 250m)" unless row['distance'] =~ /\d+m/
|
||||
end
|
||||
got['distance'] = instructions ? "#{json['route_summary']['total_distance'].to_s}m" : ''
|
||||
end
|
||||
if table.headers.include?('time')
|
||||
raise "*** Time must be specied in seconds. (ex: 60s)" unless row['time'] =~ /\d+s/
|
||||
got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : ''
|
||||
end
|
||||
if table.headers.include?('speed')
|
||||
if row['speed'] != '' && instructions
|
||||
raise "*** Speed must be specied in km/h. (ex: 50 km/h)" unless row['speed'] =~ /\d+ km\/h/
|
||||
time = json['route_summary']['total_time']
|
||||
distance = json['route_summary']['total_distance']
|
||||
speed = time>0 ? (3.6*distance/time).round : nil
|
||||
got['speed'] = "#{speed} km/h"
|
||||
else
|
||||
got['speed'] = ''
|
||||
end
|
||||
end
|
||||
if table.headers.include? 'bearing'
|
||||
got['bearing'] = instructions ? bearings : ''
|
||||
end
|
||||
if table.headers.include? 'compass'
|
||||
got['compass'] = instructions ? compasses : ''
|
||||
end
|
||||
if table.headers.include? 'turns'
|
||||
got['turns'] = instructions ? turns : ''
|
||||
end
|
||||
if table.headers.include? 'modes'
|
||||
got['modes'] = instructions ? modes : ''
|
||||
end
|
||||
if table.headers.include? 'times'
|
||||
got['times'] = instructions ? times : ''
|
||||
end
|
||||
if table.headers.include? 'distances'
|
||||
got['distances'] = instructions ? distances : ''
|
||||
end
|
||||
end
|
||||
|
||||
ok = true
|
||||
row.keys.each do |key|
|
||||
if FuzzyMatch.match got[key], row[key]
|
||||
got[key] = row[key]
|
||||
else
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
|
||||
unless ok
|
||||
log_fail row,got, { 'route' => {:query => @query, :response => response} }
|
||||
end
|
||||
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
|
||||
When /^I route (\d+) times I should get$/ do |n,table|
|
||||
ok = true
|
||||
n.to_i.times do
|
||||
ok = false unless step "I route I should get", table
|
||||
end
|
||||
ok
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
var assert = require('assert');
|
||||
|
||||
module.exports = function () {
|
||||
this.Then(/^I should get a valid timestamp/, (callback) => {
|
||||
this.ShouldGetAResponse();
|
||||
this.ShouldBeValidJSON((err) => {
|
||||
this.ShouldBeWellFormed();
|
||||
assert.equal(typeof this.json.timestamp, 'string');
|
||||
assert.equal(this.json.timestamp, '2000-01-01T00:00:00Z');
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
Then /^I should get a valid timestamp/ do
|
||||
step "I should get a response"
|
||||
step "response should be valid JSON"
|
||||
step "response should be well-formed"
|
||||
expect(@json['timestamp'].class).to eq(String)
|
||||
expect(@json['timestamp']).to eq("2000-01-01T00:00:00Z")
|
||||
end
|
||||
@@ -0,0 +1,136 @@
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I plan a trip I should get$/, (table, callback) => {
|
||||
var got;
|
||||
|
||||
this.reprocessAndLoadData(() => {
|
||||
var testRow = (row, ri, cb) => {
|
||||
var afterRequest = (err, res) => {
|
||||
if (err) return cb(err);
|
||||
var headers = new Set(table.raw()[0]);
|
||||
|
||||
for (var k in row) {
|
||||
var match = k.match(/param:(.*)/);
|
||||
if (match) {
|
||||
if (row[k] === '(nil)') {
|
||||
params[match[1]] = null;
|
||||
} else if (row[k]) {
|
||||
params[match[1]] = [row[k]];
|
||||
}
|
||||
|
||||
got[k] = row[k];
|
||||
}
|
||||
}
|
||||
|
||||
var json;
|
||||
if (res.body.length) {
|
||||
json = JSON.parse(res.body);
|
||||
}
|
||||
|
||||
if (headers.has('status')) {
|
||||
got.status = json.status.toString();
|
||||
}
|
||||
|
||||
if (headers.has('message')) {
|
||||
got.message = json.status_message;
|
||||
}
|
||||
|
||||
if (headers.has('#')) {
|
||||
// comment column
|
||||
got['#'] = row['#'];
|
||||
}
|
||||
|
||||
var subTrips;
|
||||
if (res.statusCode === 200) {
|
||||
if (headers.has('trips')) {
|
||||
subTrips = json.trips.filter(t => !!t).map(sub => sub.via_points);
|
||||
}
|
||||
}
|
||||
|
||||
var ok = true,
|
||||
encodedResult = '',
|
||||
extendedTarget = '';
|
||||
|
||||
row.trips.split(',').forEach((sub, si) => {
|
||||
if (si >= subTrips.length) {
|
||||
ok = false;
|
||||
} else {
|
||||
ok = false;
|
||||
// TODO: Check all rotations of the round trip
|
||||
for (var ni=0; ni<sub.length; ni++) {
|
||||
var node = this.findNodeByName(sub[ni]),
|
||||
outNode = subTrips[si][ni];
|
||||
if (this.FuzzyMatch.matchLocation(outNode, node)) {
|
||||
encodedResult += sub[ni];
|
||||
extendedTarget += sub[ni];
|
||||
ok = true;
|
||||
} else {
|
||||
encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]);
|
||||
extendedTarget += util.format('%s [%d,%d]', sub[ni], node.lat, node.lon);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (ok) {
|
||||
got.trips = row.trips;
|
||||
got.via_points = row.via_points;
|
||||
} else {
|
||||
got.trips = encodedResult;
|
||||
got.trips = extendedTarget;
|
||||
this.logFail(row, got, { trip: { query: this.query, response: res }});
|
||||
}
|
||||
|
||||
ok = true;
|
||||
|
||||
for (var key in row) {
|
||||
if (this.FuzzyMatch.match(got[key], row[key])) {
|
||||
got[key] = row[key];
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
this.logFail(row, got, { trip: { query: this.query, response: res }});
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
};
|
||||
|
||||
if (row.request) {
|
||||
got.request = row.request;
|
||||
this.requestUrl(row.request, afterRequest);
|
||||
} else {
|
||||
var params = this.queryParams,
|
||||
waypoints = [];
|
||||
if (row.from && row.to) {
|
||||
var fromNode = this.findNodeByName(row.from);
|
||||
if (!fromNode) throw new Error(util.format('*** unknown from-node "%s"', row.from));
|
||||
waypoints.push(fromNode);
|
||||
|
||||
var toNode = this.findNodeByName(row.to);
|
||||
if (!toNode) throw new Error(util.format('*** unknown to-node "%s"', row.to));
|
||||
waypoints.push(toNode);
|
||||
|
||||
got = { from: row.from, to: row.to };
|
||||
this.requestTrip(waypoints, params, afterRequest);
|
||||
} else if (row.waypoints) {
|
||||
row.waypoints.split(',').forEach((n) => {
|
||||
var node = this.findNodeByName(n);
|
||||
if (!node) throw new Error(util.format('*** unknown waypoint node "%s"', n.trim()));
|
||||
waypoints.push(node);
|
||||
});
|
||||
got = { waypoints: row.waypoints };
|
||||
this.requestTrip(waypoints, params, afterRequest);
|
||||
} else {
|
||||
throw new Error('*** no waypoints');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,121 +0,0 @@
|
||||
When /^I plan a trip I should get$/ do |table|
|
||||
reprocess
|
||||
actual = []
|
||||
OSRMLoader.load(self,"#{contracted_file}.osrm") do
|
||||
table.hashes.each_with_index do |row,ri|
|
||||
if row['request']
|
||||
got = {'request' => row['request'] }
|
||||
response = request_url row['request']
|
||||
else
|
||||
params = @query_params
|
||||
waypoints = []
|
||||
if row['from'] and row['to']
|
||||
node = find_node_by_name(row['from'])
|
||||
raise "*** unknown from-node '#{row['from']}" unless node
|
||||
waypoints << node
|
||||
|
||||
node = find_node_by_name(row['to'])
|
||||
raise "*** unknown to-node '#{row['to']}" unless node
|
||||
waypoints << node
|
||||
|
||||
got = {'from' => row['from'], 'to' => row['to'] }
|
||||
response = request_trip waypoints, params
|
||||
elsif row['waypoints']
|
||||
row['waypoints'].split(',').each do |n|
|
||||
node = find_node_by_name(n.strip)
|
||||
raise "*** unknown waypoint node '#{n.strip}" unless node
|
||||
waypoints << node
|
||||
end
|
||||
got = {'waypoints' => row['waypoints'] }
|
||||
response = request_trip waypoints, params
|
||||
else
|
||||
raise "*** no waypoints"
|
||||
end
|
||||
end
|
||||
|
||||
row.each_pair do |k,v|
|
||||
if k =~ /param:(.*)/
|
||||
if v=='(nil)'
|
||||
params[$1]=nil
|
||||
elsif v!=nil
|
||||
params[$1]=[v]
|
||||
end
|
||||
got[k]=v
|
||||
end
|
||||
end
|
||||
|
||||
if response.body.empty? == false
|
||||
json = JSON.parse response.body
|
||||
end
|
||||
|
||||
if table.headers.include? 'status'
|
||||
got['status'] = json['status'].to_s
|
||||
end
|
||||
if table.headers.include? 'message'
|
||||
got['message'] = json['status_message']
|
||||
end
|
||||
if table.headers.include? '#' # comment column
|
||||
got['#'] = row['#'] # copy value so it always match
|
||||
end
|
||||
|
||||
if response.code == "200"
|
||||
if table.headers.include? 'trips'
|
||||
sub_trips = json['trips'].compact.map { |sub| sub['via_points']}
|
||||
end
|
||||
end
|
||||
|
||||
######################
|
||||
ok = true
|
||||
encoded_result = ""
|
||||
extended_target = ""
|
||||
row['trips'].split(',').each_with_index do |sub, sub_idx|
|
||||
if sub_idx >= sub_trips.length
|
||||
ok = false
|
||||
break
|
||||
end
|
||||
|
||||
ok = false;
|
||||
#TODO: Check all rotations of the round trip
|
||||
sub.length.times do |node_idx|
|
||||
node = find_node_by_name(sub[node_idx])
|
||||
out_node = sub_trips[sub_idx][node_idx]
|
||||
if FuzzyMatch.match_location out_node, node
|
||||
encoded_result += sub[node_idx]
|
||||
extended_target += sub[node_idx]
|
||||
ok = true
|
||||
else
|
||||
encoded_result += "? [#{out_node[0]},#{out_node[1]}]"
|
||||
extended_target += "#{sub[node_idx]} [#{node.lat},#{node.lon}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ok
|
||||
got['trips'] = row['trips']
|
||||
got['via_points'] = row['via_points']
|
||||
else
|
||||
got['trips'] = encoded_result
|
||||
row['trips'] = extended_target
|
||||
log_fail row,got, { 'trip' => {:query => @query, :response => response} }
|
||||
end
|
||||
|
||||
|
||||
ok = true
|
||||
row.keys.each do |key|
|
||||
if FuzzyMatch.match got[key], row[key]
|
||||
got[key] = row[key]
|
||||
else
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
|
||||
unless ok
|
||||
log_fail row,got, { 'trip' => {:query => @query, :response => response} }
|
||||
end
|
||||
|
||||
actual << got
|
||||
end
|
||||
end
|
||||
table.diff! actual
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user