Merges node-osrm into repository

Build with

    cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_NODE_BINDINGS=On -DENABLE_MASON=On
This commit is contained in:
Daniel J. Hofmann
2017-03-01 18:27:57 +01:00
committed by Patrick Niklaus
parent ff238c2724
commit 2351b5a084
53 changed files with 4871 additions and 244 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
DATA_NAME:=monaco
DATA_NAME:=berlin
DATA_URL:=https://s3.amazonaws.com/mapbox/osrm/testing/$(DATA_NAME).osm.pbf
DATA_POLY_URL:=https://s3.amazonaws.com/mapbox/osrm/testing/$(DATA_NAME).poly
OSRM_BUILD_DIR?=../../build
+2 -2
View File
@@ -1,2 +1,2 @@
2b8dd9343d5e615afc9c67bcc7028a63 monaco.osm.pbf
b0788991ab3791d53c1c20b6281f81ad monaco.poly
54707104e9f411d1a3032c00fb1276c6 berlin.osm.pbf
031d988f23fc2a30371c9ef8d2a49bae berlin.poly
+58
View File
@@ -0,0 +1,58 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
test('constructor: throws if new keyword is not used', function(assert) {
assert.plan(1);
assert.throws(function() { OSRM(); },
/Cannot call constructor as function, you need to use 'new' keyword/);
});
test('constructor: uses defaults with no parameter', function(assert) {
assert.plan(1);
var osrm = new OSRM();
assert.ok(osrm);
});
test('constructor: does not accept more than one parameter', function(assert) {
assert.plan(1);
assert.throws(function() { new OSRM({}, {}); },
/Only accepts one parameter/);
});
test('constructor: throws if necessary files do not exist', function(assert) {
assert.plan(1);
assert.throws(function() { new OSRM("missing.osrm"); },
/Invalid file paths/);
});
test('constructor: takes a shared memory argument', function(assert) {
assert.plan(1);
var osrm = new OSRM({path: berlin_path, shared_memory: false});
assert.ok(osrm);
});
test('constructor: throws if shared_memory==false with no path defined', function(assert) {
assert.plan(1);
assert.throws(function() { var osrm = new OSRM({shared_memory: false}); },
/Shared_memory must be enabled if no path is specified/);
});
test('constructor: throws if given a non-bool shared_memory option', function(assert) {
assert.plan(1);
assert.throws(function() { var osrm = new OSRM({path: berlin_path, shared_memory: "a"}); },
/Shared_memory option must be a boolean/);
});
test('constructor: throws if given a non-string/obj argument', function(assert) {
assert.plan(1);
assert.throws(function() { var osrm = new OSRM(true); },
/Parameter must be a path or options object/);
});
require('./route.js');
require('./trip.js');
require('./match.js');
require('./tile.js');
require('./table.js');
require('./nearest.js');
+195
View File
@@ -0,0 +1,195 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
test('match: match in Berlin', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
timestamps: [1424684612, 1424684616, 1424684620]
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.matchings.length, 1);
assert.ok(response.matchings.every(function(m) {
return !!m.distance && !!m.duration && Array.isArray(m.legs) && !!m.geometry && m.confidence > 0;
}))
assert.equal(response.tracepoints.length, 3);
assert.ok(response.tracepoints.every(function(t) {
return !!t.hint && !isNaN(t.matchings_index) && !isNaN(t.waypoint_index) && !!t.name;
}));
});
});
test('match: match in Berlin without timestamps', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]]
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.tracepoints.length, 3);
assert.equal(response.matchings.length, 1);
});
});
test('match: match in Berlin without geometry compression', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
geometries: 'geojson'
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.matchings.length, 1);
assert.ok(response.matchings[0].geometry instanceof Object);
assert.ok(Array.isArray(response.matchings[0].geometry.coordinates));
});
});
test('match: match in Berlin with geometry compression', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]]
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.matchings.length, 1);
assert.equal('string', typeof response.matchings[0].geometry);
});
});
test('match: match in Berlin with speed annotations options', function(assert) {
assert.plan(12);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
timestamps: [1424684612, 1424684616, 1424684620],
radiuses: [4.07, 4.07, 4.07],
steps: true,
annotations: ['speed'],
overview: 'false',
geometries: 'geojson'
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.matchings.length, 1);
assert.ok(response.matchings[0].confidence > 0, 'has confidence');
assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.speed; }), 'every leg has annotations for speed');
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.weight; }), 'has no annotations for weight')
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.datasources; }), 'has no annotations for datasources')
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'has no annotations for duration')
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'has no annotations for distance')
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.nodes; }), 'has no annotations for nodes')
assert.equal(undefined, response.matchings[0].geometry);
});
});
test('match: match in Berlin with several (duration, distance, nodes) annotations options', function(assert) {
assert.plan(12);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
timestamps: [1424684612, 1424684616, 1424684620],
radiuses: [4.07, 4.07, 4.07],
steps: true,
annotations: ['duration','distance','nodes'],
overview: 'false',
geometries: 'geojson'
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.matchings.length, 1);
assert.ok(response.matchings[0].confidence > 0, 'has confidence');
assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'every leg has annotations for distance');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'every leg has annotations for durations');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.nodes; }), 'every leg has annotations for nodes');
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.weight; }), 'has no annotations for weight')
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.datasources; }), 'has no annotations for datasources')
assert.notOk(response.matchings[0].legs.every((l) => {return l.annotation.speed; }), 'has no annotations for speed')
assert.equal(undefined, response.matchings[0].geometry);
});
});
test('match: match in Berlin with all options', function(assert) {
assert.plan(8);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
timestamps: [1424684612, 1424684616, 1424684620],
radiuses: [4.07, 4.07, 4.07],
steps: true,
annotations: true,
overview: 'false',
geometries: 'geojson'
};
osrm.match(options, function(err, response) {
assert.ifError(err);
assert.equal(response.matchings.length, 1);
assert.ok(response.matchings[0].confidence > 0, 'has confidence');
assert.ok(response.matchings[0].legs.every((l) => {return l.steps.length > 0; }), 'every leg has steps');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation; }), 'every leg has annotations');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.distance; }), 'every leg has annotations for distance');
assert.ok(response.matchings[0].legs.every((l) => {return l.annotation.duration; }), 'every leg has annotations for durations');
assert.equal(undefined, response.matchings[0].geometry);
});
});
test('match: throws on missing arguments', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.match({}) },
/Two arguments required/);
});
test('match: throws on non-object arg', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.match(null, function(err, response) {}) },
/First arg must be an object/);
});
test('match: throws on invalid coordinates param', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: ''
};
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252,52.542648]];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/At least two coordinates must be provided/);
options.coordinates = [13.393252,52.542648];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252],[52.542648]];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
});
test('match: throws on invalid timestamps param', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]],
timestamps: 'timestamps'
};
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Timestamps must be an array of integers \(or undefined\)/);
options.timestamps = ['invalid', 'timestamp', 'array'];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Timestamps array items must be numbers/);
options.timestamps = [1424684612, 1424684616];
assert.throws(function() { osrm.match(options, function(err, response) {}) },
/Timestamp array must have the same size as the coordinates array/);
});
+51
View File
@@ -0,0 +1,51 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
test('nearest', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
osrm.nearest({
coordinates: [[13.333086, 52.4224]]
}, function(err, result) {
assert.ifError(err);
assert.equal(result.waypoints.length, 1);
assert.equal(result.waypoints[0].location.length, 2);
assert.ok(result.waypoints[0].hasOwnProperty('name'));
});
});
test('nearest: can ask for multiple nearest pts', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
osrm.nearest({
coordinates: [[13.333086, 52.4224]],
number: 3
}, function(err, result) {
assert.ifError(err);
assert.equal(result.waypoints.length, 3);
});
});
test('nearest: throws on invalid args', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
var options = {};
assert.throws(function() { osrm.nearest(options); },
/Two arguments required/);
assert.throws(function() { osrm.nearest(null, function(err, res) {}); },
/First arg must be an object/);
options.coordinates = [52.4224];
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Coordinates must be an array of /);
options.coordinates = [[13.333086, 52.4224],[13.333086, 52.5224]];
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Exactly one coordinate pair must be provided/);
options.coordinates = [[13.333086, 52.4224]];
options.number = 3.14159;
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Number must be an integer greater than or equal to 1/);
options.number = 0;
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
/Number must be an integer greater than or equal to 1/);
});
+8
View File
@@ -0,0 +1,8 @@
var path = require('path');
if (process.env.OSRM_DATA_PATH !== undefined) {
exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "berlin_CH.osrm");
console.log('Setting custom data path to ' + exports.data_path);
} else {
exports.data_path = path.resolve(path.join(__dirname, "../data/berlin_CH.osrm"));
}
+471
View File
@@ -0,0 +1,471 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
test('route: routes Berlin', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, function(err, route) {
assert.ifError(err);
assert.ok(route.waypoints);
assert.ok(route.routes);
assert.ok(route.routes.length);
assert.ok(route.routes[0].geometry);
});
});
test('route: throws with too few or invalid args', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}) },
/Two arguments required/);
assert.throws(function() { osrm.route(null, function(err, route) {}) },
/First arg must be an object/);
assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, true)},
/last argument must be a callback function/);
});
test('route: provides no alternatives by default, but when requested', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
var options = {coordinates: [[13.302383,52.490516], [13.418427,52.522070]]};
osrm.route(options, function(err, route) {
assert.ifError(err);
assert.ok(route.routes);
assert.equal(route.routes.length, 1);
});
options.alternatives = true;
osrm.route(options, function(err, route) {
assert.ifError(err);
assert.ok(route.routes);
assert.equal(route.routes.length, 2);
});
});
test('route: throws with bad params', function(assert) {
assert.plan(11);
var osrm = new OSRM(berlin_path);
assert.throws(function () { osrm.route({coordinates: []}, function(err) {}) });
assert.throws(function() { osrm.route({}, function(err, route) {}) },
/Must provide a coordinates property/);
assert.throws(function() { osrm.route({coordinates: null}, function(err, route) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
assert.throws(function() { osrm.route({coordinates: [13.438640, 52.519930]}, function(err, route) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
assert.throws(function() { osrm.route({coordinates: [[true, '52.519930'], [13.438640, 52.519930]]}, function(err, route) {}) },
/Each member of a coordinate pair must be a number/);
assert.throws(function() { osrm.route({coordinates: [[213.43864,252.51993],[413.415852,552.513191]]}, function(err, route) {}) },
/Lng\/Lat coordinates must be within world bounds \(-180 < lng < 180, -90 < lat < 90\)/);
assert.throws(function() { osrm.route({coordinates: [[13.438640], [52.519930]]}, function(err, route) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]], hints: null}, function(err, route) {}) },
/Hints must be an array of strings\/null/);
assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]], steps: null}, function(err, route) {}) });
assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]], annotations: null}, function(err, route) {}) });
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
alternateRoute: false,
hints: [13.438640, 52.519930]
};
assert.throws(function() { osrm.route(options, function(err, route) {}) },
/Hint must be null or string/);
});
test('route: routes Berlin using shared memory', function(assert) {
assert.plan(2);
var osrm = new OSRM();
osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, function(err, route) {
assert.ifError(err);
assert.ok(Array.isArray(route.routes));
});
});
test('route: routes Berlin with geometry compression', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
};
osrm.route(options, function(err, route) {
assert.ifError(err);
assert.equal('string', typeof route.routes[0].geometry);
});
});
test('route: routes Berlin without geometry compression', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
geometries: 'geojson'
};
osrm.route(options, function(err, route) {
assert.ifError(err);
assert.ok(Array.isArray(route.routes));
assert.ok(Array.isArray(route.routes[0].geometry.coordinates));
assert.equal(route.routes[0].geometry.type, 'LineString');
});
});
test('Test polyline6 geometries option', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
continue_straight: false,
overview: 'false',
geometries: 'polyline6',
steps: true
};
osrm.route(options, function(err, first) {
assert.ifError(err);
assert.ok(first.routes);
assert.equal(first.routes.length, 1);
assert.notOk(first.routes[0].geometry);
assert.ok(first.routes[0].legs[0]);
assert.equal(typeof first.routes[0].legs[0].steps[0].geometry, 'string');
});
});
test('route: routes Berlin with speed annotations options', function(assert) {
assert.plan(17);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
continue_straight: false,
overview: 'false',
geometries: 'polyline',
steps: true,
annotations: ['speed']
};
osrm.route(options, function(err, first) {
assert.ifError(err);
assert.ok(first.routes);
assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; }));
assert.equal(first.routes.length, 1);
assert.notOk(first.routes[0].geometry);
assert.ok(first.routes[0].legs[0]);
assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
assert.ok(first.routes[0].legs.every(l => { return l.annotation.speed;}), 'every leg has annotations for speed');
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight')
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources')
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.duration; }), 'has no annotations for duration')
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.distance; }), 'has no annotations for distance')
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.nodes; }), 'has no annotations for nodes')
options.overview = 'full';
osrm.route(options, function(err, full) {
assert.ifError(err);
options.overview = 'simplified';
osrm.route(options, function(err, simplified) {
assert.ifError(err);
assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry);
});
});
});
});
test('route: routes Berlin with several (duration, distance, nodes) annotations options', function(assert) {
assert.plan(17);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
continue_straight: false,
overview: 'false',
geometries: 'polyline',
steps: true,
annotations: ['duration','distance','nodes']
};
osrm.route(options, function(err, first) {
assert.ifError(err);
assert.ok(first.routes);
assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; }));
assert.equal(first.routes.length, 1);
assert.notOk(first.routes[0].geometry);
assert.ok(first.routes[0].legs[0]);
assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance');
assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations');
assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes');
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight')
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources')
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'has no annotations for speed')
options.overview = 'full';
osrm.route(options, function(err, full) {
assert.ifError(err);
options.overview = 'simplified';
osrm.route(options, function(err, simplified) {
assert.ifError(err);
assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry);
});
});
});
});
test('route: routes Berlin with options', function(assert) {
assert.plan(11);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
continue_straight: false,
overview: 'false',
geometries: 'polyline',
steps: true,
annotations: true
};
osrm.route(options, function(err, first) {
assert.ifError(err);
assert.ok(first.routes);
assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; }));
assert.equal(first.routes.length, 1);
assert.notOk(first.routes[0].geometry);
assert.ok(first.routes[0].legs[0]);
assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
options.overview = 'full';
osrm.route(options, function(err, full) {
assert.ifError(err);
options.overview = 'simplified';
osrm.route(options, function(err, simplified) {
assert.ifError(err);
assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry);
});
});
});
});
test('route: routes Berlin with options', function(assert) {
assert.plan(11);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
continue_straight: false,
overview: 'false',
geometries: 'polyline',
steps: true,
annotations: true
};
osrm.route(options, function(err, first) {
assert.ifError(err);
assert.ok(first.routes);
assert.ok(first.routes[0].legs.every(function(l) { return Array.isArray(l.steps) && l.steps.length > 0; }));
assert.equal(first.routes.length, 1);
assert.notOk(first.routes[0].geometry);
assert.ok(first.routes[0].legs[0]);
assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
options.overview = 'full';
osrm.route(options, function(err, full) {
assert.ifError(err);
options.overview = 'simplified';
osrm.route(options, function(err, simplified) {
assert.ifError(err);
assert.notEqual(full.routes[0].geometry, simplified.routes[0].geometry);
});
});
});
});
test('route: invalid route options', function(assert) {
assert.plan(8);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
continue_straight: []
}, function(err, route) {}); },
/must be boolean/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
alternatives: []
}, function(err, route) {}); },
/must be boolean/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
geometries: true
}, function(err, route) {}); },
/Geometries must be a string: \[polyline, polyline6, geojson\]/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
overview: false
}, function(err, route) {}); },
/Overview must be a string: \[simplified, full, false\]/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
overview: false
}, function(err, route) {}); },
/Overview must be a string: \[simplified, full, false\]/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
overview: 'maybe'
}, function(err, route) {}); },
/'overview' param must be one of \[simplified, full, false\]/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
geometries: 'maybe'
}, function(err, route) {}); },
/'geometries' param must be one of \[polyline, polyline6, geojson\]/);
assert.throws(function() { osrm.route({
coordinates: [[NaN, -NaN],[Infinity, -Infinity]]
}, function(err, route) {}); },
/Lng\/Lat coordinates must be valid numbers/);
});
test('route: integer bearing values no longer supported', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [200, 250],
};
assert.throws(function() { osrm.route(options, function(err, route) {}); },
/Bearing must be an array of \[bearing, range\] or null/);
});
test('route: valid bearing values', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [[200, 180], [250, 180]],
};
osrm.route(options, function(err, route) {
assert.ifError(err);
assert.ok(route.routes[0]);
});
options.bearings = [null, [360, 180]];
osrm.route(options, function(err, route) {
assert.ifError(err);
assert.ok(route.routes[0]);
});
});
test('route: invalid bearing values', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [[400, 180], [-250, 180]],
}, function(err, route) {}) },
/Bearing values need to be in range 0..360, 0..180/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [[200], [250, 180]],
}, function(err, route) {}) },
/Bearing must be an array of/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [[400, 109], [100, 720]],
}, function(err, route) {}) },
/Bearing values need to be in range 0..360, 0..180/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: 400,
}, function(err, route) {}) },
/Bearings must be an array of arrays of numbers/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [[100, 100]],
}, function(err, route) {}) },
/Bearings array must have the same length as coordinates array/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
bearings: [Infinity, Infinity],
}, function(err, route) {}) },
/Bearing must be an array of \[bearing, range\] or null/);
});
test('route: routes Berlin with hints', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]]
};
osrm.route(options, function(err, first) {
assert.ifError(err);
assert.ok(first.waypoints);
var hints = first.waypoints.map(function(wp) { return wp.hint; });
assert.ok(hints.every(function(h) { return typeof h === 'string'; }));
options.hints = hints;
osrm.route(options, function(err, second) {
assert.ifError(err);
assert.deepEqual(first, second);
});
});
});
test('route: routes Berlin with null hints', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
hints: [null, null]
};
osrm.route(options, function(err, route) {
assert.ifError(err);
});
});
test('route: throws on bad hints', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
hints: ['', '']
}, function(err, route) {})}, /Hint cannot be an empty string/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
hints: [null]
}, function(err, route) {})}, /Hints array must have the same length as coordinates array/);
});
test('route: routes Berlin with valid radius values', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
radiuses: [100, 100]
};
osrm.route(options, function(err, route) {
assert.ifError(err);
});
options.radiuses = [null, null];
osrm.route(options, function(err, route) {
assert.ifError(err);
});
options.radiuses = [100, null];
osrm.route(options, function(err, route) {
assert.ifError(err);
});
});
test('route: throws on bad radiuses', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
radiuses: [10, 10]
};
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
radiuses: 10
}, function(err, route) {}) },
/Radiuses must be an array of non-negative doubles or null/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
radiuses: ['magic', 'numbers']
}, function(err, route) {}) },
/Radius must be non-negative double or null/);
assert.throws(function() { osrm.route({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
radiuses: [10]
}, function(err, route) {}) },
/Radiuses array must have the same length as coordinates array/);
});
+161
View File
@@ -0,0 +1,161 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
test('table: distance table in Berlin', function(assert) {
assert.plan(9);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]]
};
osrm.table(options, function(err, table) {
assert.ifError(err);
assert.ok(Array.isArray(table.durations), 'result must be an array');
var row_count = table.durations.length;
for (var i = 0; i < row_count; ++i) {
var column = table.durations[i];
var column_count = column.length;
assert.equal(row_count, column_count);
for (var j = 0; j < column_count; ++j) {
if (i == j) {
// check that diagonal is zero
assert.equal(0, column[j], 'diagonal must be zero');
} else {
// everything else is non-zero
assert.notEqual(0, column[j], 'other entries must be non-zero');
}
}
}
assert.equal(options.coordinates.length, row_count);
});
});
test('table: distance table in Berlin with sources/destinations', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
sources: [0],
destinations: [0,1]
};
osrm.table(options, function(err, table) {
assert.ifError(err);
assert.ok(Array.isArray(table.durations), 'result must be an array');
var row_count = table.durations.length;
for (var i = 0; i < row_count; ++i) {
var column = table.durations[i];
var column_count = column.length;
assert.equal(options.destinations.length, column_count);
for (var j = 0; j < column_count; ++j) {
if (i == j) {
// check that diagonal is zero
assert.equal(0, column[j], 'diagonal must be zero');
} else {
// everything else is non-zero
assert.notEqual(0, column[j], 'other entries must be non-zero');
}
}
}
assert.equal(options.sources.length, row_count);
});
});
test('table: throws on invalid arguments', function(assert) {
assert.plan(14);
var osrm = new OSRM(berlin_path);
var options = {};
assert.throws(function() { osrm.table(options); },
/Two arguments required/);
options.coordinates = null;
assert.throws(function() { osrm.table(options, function() {}); },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252,52.542648]];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/At least two coordinates must be provided/);
options.coordinates = [13.393252,52.542648];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252],[52.542648]];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
options.coordinates = [[13.393252,52.542648],[13.393252,52.542648]];
options.sources = true;
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Sources must be an array of indices \(or undefined\)/);
options.sources = [0, 4];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Source indices must be less than or equal to the number of coordinates/);
options.sources = [0.3, 1.1];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Source must be an integer/);
options.destinations = true;
delete options.sources;
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Destinations must be an array of indices \(or undefined\)/);
options.destinations = [0, 4];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Destination indices must be less than or equal to the number of coordinates/);
options.destinations = [0.3, 1.1];
assert.throws(function() { osrm.table(options, function(err, response) {}) },
/Destination must be an integer/);
// does not throw: the following two have been changed in OSRM v5
options.sources = [0, 1];
delete options.destinations;
assert.doesNotThrow(function() { osrm.table(options, function(err, response) {}) },
/Both sources and destinations need to be specified/);
options.destinations = [0, 1];
assert.doesNotThrow(function() { osrm.table(options, function(err, response) {}) },
/You can either specify sources and destinations, or coordinates/);
assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]], generate_hints: null}, function(err, route) {}) },
/generate_hints must be of type Boolean/);
});
test('table: throws on invalid arguments', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.table(null, function() {}); },
/First arg must be an object/);
});
test('table: distance table in Berlin with hints', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
generate_hints: true // true is default but be explicit here
};
osrm.table(options, function(err, table) {
console.log(table);
assert.ifError(err);
function assertHasHints(waypoint) {
assert.notStrictEqual(waypoint.hint, undefined);
}
table.sources.map(assertHasHints);
table.destinations.map(assertHasHints);
});
});
test('table: distance table in Berlin without hints', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
generate_hints: false // true is default
};
osrm.table(options, function(err, table) {
assert.ifError(err);
function assertHasNoHints(waypoint) {
assert.strictEqual(waypoint.hint, undefined);
}
table.sources.map(assertHasNoHints);
table.destinations.map(assertHasNoHints);
});
});
+23
View File
@@ -0,0 +1,23 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = "test/data/berlin-latest.osrm";
test.test('tile check size coarse', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
osrm.tile([17603, 10747, 15], function(err, result) {
assert.ifError(err);
assert.ok(result.length > 35000);
});
});
// FIXME the size of the tile that is returned depends on the architecture
// See issue #3343 in osrm-backend
test.skip('tile', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
osrm.tile([17603, 10747, 15], function(err, result) {
assert.ifError(err);
assert.equal(result.length, 35970);
});
});
+333
View File
@@ -0,0 +1,333 @@
var OSRM = require('../../');
var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path;
test('trip: trip in Berlin', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
osrm.trip({coordinates: [[13.36761474609375,52.51663871100423],[13.374481201171875,52.506191342034576]]}, function(err, trip) {
assert.ifError(err);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(trip.trips[t].geometry);
}
});
});
test('trip: trip with many locations in Berlin', function(assert) {
assert.plan(4);
var osrm = new OSRM(berlin_path);
var opts = {coordinates: [[13.36761474609375,52.51663871100423],[13.374481201171875,52.506191342034576],[13.404693603515625,52.50535544522142],[13.388900756835938,52.50159371284434],[13.386840820312498,52.518727886767266],[13.4088134765625,52.528754547664185],[13.41156005859375,52.51705655410405],[13.420486450195312,52.512042174642346],[13.413619995117188,52.50368360390624],[13.36212158203125,52.504101570196205],[13.35113525390625,52.52248815280757],[13.36761474609375,52.53460237630516],[13.383407592773438,52.53710835019913],[13.392333984375,52.536690697815736],[13.42529296875,52.532931647583325],[13.399200439453125,52.52415927884915],[13.390960693359375,52.51956352925745],[13.375167846679688,52.533349335723294],[13.37860107421875,52.520399155853454],[13.355255126953125,52.52081696319122],[13.385467529296875,52.5143405029259],[13.398857116699219,52.513086884218325],[13.399200439453125,52.50744515744915],[13.409500122070312,52.49783165855699],[13.424949645996094,52.500339730516934],[13.440055847167969,52.50786308797268],[13.428382873535156,52.511624283857785],[13.437652587890625,52.50451953251202],[13.443145751953125,52.5199813445422],[13.431129455566406,52.52520370034151],[13.418426513671875,52.52896341209634],[13.429069519042969,52.517474393230245],[13.418083190917969,52.528127948407935],[13.405036926269531,52.52833681581998],[13.384437561035156,52.53084314728766],[13.374481201171875,52.53084314728766],[13.3978271484375,52.532305107923925],[13.418769836425781,52.526039219655445],[13.441085815429688,52.51642978796417],[13.448638916015625,52.51601193890388],[13.44623565673828,52.50535544522142],[13.430442810058594,52.502638670794546],[13.358688354492188,52.520190250694526],[13.358001708984375,52.531887409851336],[13.367271423339842,52.528545682238736],[13.387870788574219,52.52958999943304],[13.406410217285156,52.53961418106945],[13.399543762207031,52.50556442091497],[13.374824523925781,52.50389258754797],[13.386154174804688,52.51099744023003],[13.40229034423828,52.49657756892365]]
};
osrm.trip(opts, function(err, trip) {
assert.ifError(err);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(trip.trips[t].geometry);
}
assert.equal(opts.coordinates.length, trip.waypoints.length);
var indexMap = trip.waypoints.map(function(wp, i) {
return [i, wp.waypoint_index];
});
assert.ok(!indexMap.every(function(tuple) { return tuple[0] === tuple[1]; }));
});
});
test('trip: throws with too few or invalid args', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
assert.throws(function() { osrm.trip({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}) },
/Two arguments required/);
assert.throws(function() { osrm.trip(null, function(err, trip) {}) },
/First arg must be an object/);
});
test('trip: throws with bad params', function(assert) {
assert.plan(14);
var osrm = new OSRM(berlin_path);
assert.throws(function () { osrm.trip({coordinates: []}, function(err) {}) });
assert.throws(function() { osrm.trip({}, function(err, trip) {}) },
/Must provide a coordinates property/);
assert.throws(function() { osrm.trip({
coordinates: null
}, function(err, trip) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
assert.throws(function() { osrm.trip({
coordinates: [13.438640, 52.519930]
}, function(err, trip) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
assert.throws(function() { osrm.trip({
coordinates: [[13.438640], [52.519930]]
}, function(err, trip) {}) },
/Coordinates must be an array of \(lon\/lat\) pairs/);
assert.throws(function() { osrm.trip({
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
hints: null
}, function(err, trip) {}) },
/Hints must be an array of strings\/null/);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
printInstructions: false,
hints: [13.438640, 52.519930]
};
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/Hint must be null or string/);
options.hints = [null];
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/Hints array must have the same length as coordinates array/);
delete options.hints;
options.geometries = 'false';
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/'geometries' param must be one of \[polyline, polyline6, geojson\]/);
delete options.geometries;
options.source = false;
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/Source must be a string: \[any, first\]/);
options.source = 'false';
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/'source' param must be one of \[any, first\]/);
delete options.source;
options.destination = true;
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/Destination must be a string: \[any, last\]/);
options.destination = 'true';
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/'destination' param must be one of \[any, last\]/);
options.roundtrip = 'any';
assert.throws(function() { osrm.trip(options, function(err, trip) {}); },
/'roundtrip' param must be a boolean/);
});
test('trip: routes Berlin using shared memory', function(assert) {
assert.plan(2);
var osrm = new OSRM();
osrm.trip({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, function(err, trip) {
assert.ifError(err);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(trip.trips[t].geometry);
}
});
});
test('trip: routes Berlin with hints', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
steps: false
};
osrm.trip(options, function(err, first) {
assert.ifError(err);
for (t = 0; t < first.trips.length; t++) {
assert.ok(first.trips[t].geometry);
}
var hints = first.waypoints.map(function(wp) { return wp.hint; });
assert.ok(hints.every(function(h) { return typeof h === 'string'; }));
options.hints = hints;
osrm.trip(options, function(err, second) {
assert.ifError(err);
assert.deepEqual(first, second);
});
});
});
test('trip: trip through Berlin with geometry compression', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]]
};
osrm.trip(options, function(err, trip) {
assert.ifError(err);
for (t = 0; t < trip.trips.length; t++) {
assert.equal('string', typeof trip.trips[t].geometry);
}
});
});
test('trip: trip through Berlin without geometry compression', function(assert) {
assert.plan(2);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
geometries: 'geojson'
};
osrm.trip(options, function(err, trip) {
assert.ifError(err);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(Array.isArray(trip.trips[t].geometry.coordinates));
}
});
});
test('trip: trip through Berlin with speed annotations options', function(assert) {
assert.plan(12);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
steps: true,
annotations: ['speed'],
overview: 'false'
};
osrm.trip(options, function(err, trip) {
assert.ifError(err);
assert.equal(trip.trips.length, 1);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(trip.trips[t]);
assert.ok(trip.trips[t].legs.every(function(l) { return l.steps.length > 0; }), 'every leg has steps')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation; }), 'every leg has annotations')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.speed; }), 'every leg has annotations for speed')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.weight; }), 'has no annotations for weight')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.datasources; }), 'has no annotations for datasources')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.duration; }), 'has no annotations for duration')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.distance; }), 'has no annotations for distance')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.nodes; }), 'has no annotations for nodes')
assert.notOk(trip.trips[t].geometry);
}
});
});
test('trip: trip through Berlin with several (duration, distance, nodes) annotations options', function(assert) {
assert.plan(12);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
steps: true,
annotations: ['duration', 'distance', 'nodes'],
overview: 'false'
};
osrm.trip(options, function(err, trip) {
assert.ifError(err);
assert.equal(trip.trips.length, 1);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(trip.trips[t]);
assert.ok(trip.trips[t].legs.every(function(l) { return l.steps.length > 0; }), 'every leg has steps')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation; }), 'every leg has annotations')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.duration; }), 'every leg has annotations for duration')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.distance; }), 'every leg has annotations for distance')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation.nodes; }), 'every leg has annotations for nodes')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.weight; }), 'has no annotations for weight')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.datasources; }), 'has no annotations for datasources')
assert.notOk(trip.trips[t].legs.every(function(l) { return l.annotation.speed; }), 'has no annotations for speed')
assert.notOk(trip.trips[t].geometry);
}
});
});
test('trip: trip through Berlin with options', function(assert) {
assert.plan(6);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
steps: true,
annotations: true,
overview: 'false'
};
osrm.trip(options, function(err, trip) {
assert.ifError(err);
assert.equal(trip.trips.length, 1);
for (t = 0; t < trip.trips.length; t++) {
assert.ok(trip.trips[t]);
assert.ok(trip.trips[t].legs.every(function(l) { return l.steps.length > 0; }), 'every leg has steps')
assert.ok(trip.trips[t].legs.every(function(l) { return l.annotation; }), 'every leg has annotations')
assert.notOk(trip.trips[t].geometry);
}
});
});
test('trip: routes Berlin with null hints', function(assert) {
assert.plan(1);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
printInstructions: false,
hints: [null, null]
};
osrm.trip(options, function(err, second) {
assert.ifError(err);
});
});
test('trip: service combinations that are not implemented', function(assert) {
assert.plan(3);
var osrm = new OSRM(berlin_path);
// fixed start, non-roundtrip
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
source: 'first',
roundtrip: false
};
osrm.trip(options, function(err, second) {
assert.equal('NotImplemented', err.message);
});
// fixed start, fixed end, non-roundtrip
options.source = 'any';
options.destination = 'any';
osrm.trip(options, function(err, second) {
assert.equal('NotImplemented', err.message);
});
// fixed end, non-roundtrip
delete options.source;
options.destination = 'last';
osrm.trip(options, function(err, second) {
assert.equal('NotImplemented', err.message);
});
});
test('trip: fixed start and end combinations', function(assert) {
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.36761474609375,52.51663871100423],[13.374481201171875,52.506191342034576]],
source: 'first',
destination: 'last',
roundtrip: false,
geometries: 'geojson'
};
// fixed start and end, non-roundtrip
osrm.trip(options, function(err, fseTrip) {
assert.ifError(err);
assert.equal(206.8, fseTrip.trips[0].duration);
assert.equal(1, fseTrip.trips.length);
var coordinates = fseTrip.trips[0].geometry.coordinates;
assert.equal(15, coordinates.length);
assert.notEqual(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1]));
});
// variations of roundtrip
var roundtripChecks = function(options) {
osrm.trip(options, function(err, trip) {
assert.ifError(err);
assert.equal(1, trip.trips.length);
assert.equal(422, Math.round(trip.trips[0].duration));
var coordinates = trip.trips[0].geometry.coordinates;
assert.equal(29, coordinates.length);
assert.equal(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1]));
});
}
// roundtrip, source and destination not specified
roundtripChecks({coordinates: options.coordinates, geometries: options.geometries});
// roundtrip, fixed destination
options.roundtrip = true;
delete options.source;
roundtripChecks(options);
//roundtrip, fixed source
delete options.destination;
options.source = 'first';
roundtripChecks(options);
// roundtrip, non-fixed source, non-fixed destination
options.source = 'any';
options.destination = 'any';
roundtripChecks(options);
assert.end();
});