Integrate MLD in node bindings
This commit is contained in:
committed by
Patrick Niklaus
parent
2cd4ba9a0a
commit
614398ed6c
+36
-4
@@ -1,6 +1,8 @@
|
||||
var OSRM = require('../../');
|
||||
var test = require('tape');
|
||||
var berlin_path = require('./osrm-data-path').data_path;
|
||||
var berlin_mld_path = require('./osrm-data-path').mld_data_path;
|
||||
var berlin_corech_path = require('./osrm-data-path').corech_data_path;
|
||||
|
||||
test('constructor: throws if new keyword is not used', function(assert) {
|
||||
assert.plan(1);
|
||||
@@ -23,7 +25,7 @@ test('constructor: does not accept more than one parameter', function(assert) {
|
||||
test('constructor: throws if necessary files do not exist', function(assert) {
|
||||
assert.plan(1);
|
||||
assert.throws(function() { new OSRM("missing.osrm"); },
|
||||
/Invalid file paths/);
|
||||
/Error opening missing.osrm.names/);
|
||||
});
|
||||
|
||||
test('constructor: takes a shared memory argument', function(assert) {
|
||||
@@ -34,22 +36,52 @@ test('constructor: takes a shared memory argument', function(assert) {
|
||||
|
||||
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}); },
|
||||
assert.throws(function() { 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"}); },
|
||||
assert.throws(function() { 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); },
|
||||
assert.throws(function() { new OSRM(true); },
|
||||
/Parameter must be a path or options object/);
|
||||
});
|
||||
|
||||
test('constructor: throws if given an unkown algorithm', function(assert) {
|
||||
assert.plan(1);
|
||||
assert.throws(function() { new OSRM({algorithm: 'Foo', shared_memory: true}); },
|
||||
/algorithm option must be one of 'CH', 'CoreCH', or 'MLD'/);
|
||||
});
|
||||
|
||||
test('constructor: throws if given an invalid algorithm', function(assert) {
|
||||
assert.plan(1);
|
||||
assert.throws(function() { new OSRM({algorithm: 3, shared_memory: true}); },
|
||||
/algorithm option must be a string and one of 'CH', 'CoreCH', or 'MLD'/);
|
||||
});
|
||||
|
||||
test('constructor: loads MLD if given as algorithm', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({algorithm: 'MLD', path: berlin_mld_path});
|
||||
assert.ok(osrm);
|
||||
});
|
||||
|
||||
test('constructor: loads CH if given as algorithm', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({algorithm: 'CH', path: berlin_path});
|
||||
assert.ok(osrm);
|
||||
});
|
||||
|
||||
test('constructor: loads CoreCH if given as algorithm', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({algorithm: 'CoreCH', path: berlin_corech_path});
|
||||
assert.ok(osrm);
|
||||
});
|
||||
|
||||
require('./route.js');
|
||||
require('./trip.js');
|
||||
require('./match.js');
|
||||
|
||||
@@ -2,7 +2,11 @@ var path = require('path');
|
||||
|
||||
if (process.env.OSRM_DATA_PATH !== undefined) {
|
||||
exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/berlin.osrm");
|
||||
exports.mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/berlin.osrm");
|
||||
exports.corech_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "corech/berlin.osrm");
|
||||
console.log('Setting custom data path to ' + exports.data_path);
|
||||
} else {
|
||||
exports.data_path = path.resolve(path.join(__dirname, "../data/ch/berlin.osrm"));
|
||||
exports.mld_data_path = path.resolve(path.join(__dirname, "../data/mld/berlin.osrm"));
|
||||
exports.corech_data_path = path.resolve(path.join(__dirname, "../data/corech/berlin.osrm"));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
var OSRM = require('../../');
|
||||
var test = require('tape');
|
||||
var berlin_path = require('./osrm-data-path').data_path;
|
||||
var berlin_mld_path = require('./osrm-data-path').mld_data_path;
|
||||
var berlin_corech_path = require('./osrm-data-path').corech_data_path;
|
||||
|
||||
test('route: routes Berlin', function(assert) {
|
||||
assert.plan(5);
|
||||
@@ -14,6 +16,30 @@ test('route: routes Berlin', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
test('route: routes Berlin on MLD', function(assert) {
|
||||
assert.plan(5);
|
||||
var osrm = new OSRM({path: berlin_mld_path, algorithm: 'MLD'});
|
||||
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: routes Berlin on CoreCH', function(assert) {
|
||||
assert.plan(5);
|
||||
var osrm = new OSRM({path: berlin_corech_path, algorithm: 'CoreCH'});
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user