2017-03-01 12:27:57 -05:00
|
|
|
var OSRM = require('../../');
|
|
|
|
var test = require('tape');
|
2017-03-29 09:28:45 -04:00
|
|
|
var data_path = require('./constants').data_path;
|
2017-08-16 17:35:02 -04:00
|
|
|
var mld_data_path = require('./constants').mld_data_path;
|
2017-03-29 09:28:45 -04:00
|
|
|
var three_test_coordinates = require('./constants').three_test_coordinates;
|
|
|
|
var two_test_coordinates = require('./constants').two_test_coordinates;
|
|
|
|
|
2017-03-01 12:27:57 -05:00
|
|
|
|
|
|
|
test('nearest', function(assert) {
|
|
|
|
assert.plan(4);
|
2017-03-29 09:28:45 -04:00
|
|
|
var osrm = new OSRM(data_path);
|
2017-03-01 12:27:57 -05:00
|
|
|
osrm.nearest({
|
2017-03-29 09:28:45 -04:00
|
|
|
coordinates: [three_test_coordinates[0]]
|
2017-03-01 12:27:57 -05:00
|
|
|
}, 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);
|
2017-03-29 09:28:45 -04:00
|
|
|
var osrm = new OSRM(data_path);
|
2017-03-01 12:27:57 -05:00
|
|
|
osrm.nearest({
|
2017-03-29 09:28:45 -04:00
|
|
|
coordinates: [three_test_coordinates[0]],
|
2017-03-01 12:27:57 -05:00
|
|
|
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);
|
2017-03-29 09:28:45 -04:00
|
|
|
var osrm = new OSRM(data_path);
|
2017-03-01 12:27:57 -05:00
|
|
|
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/);
|
2017-03-29 09:28:45 -04:00
|
|
|
options.coordinates = [43.73072];
|
2017-03-01 12:27:57 -05:00
|
|
|
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
|
|
|
/Coordinates must be an array of /);
|
2017-03-29 09:28:45 -04:00
|
|
|
options.coordinates = [three_test_coordinates[0], three_test_coordinates[1]];
|
2017-03-01 12:27:57 -05:00
|
|
|
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
|
|
|
/Exactly one coordinate pair must be provided/);
|
2017-03-29 09:28:45 -04:00
|
|
|
options.coordinates = [three_test_coordinates[0]];
|
2017-03-01 12:27:57 -05:00
|
|
|
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/);
|
|
|
|
});
|
2017-08-16 17:35:02 -04:00
|
|
|
|
|
|
|
test('nearest: nearest in Monaco without motorways', function(assert) {
|
|
|
|
assert.plan(2);
|
|
|
|
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
|
|
|
var options = {
|
|
|
|
coordinates: [two_test_coordinates[0]],
|
|
|
|
exclude: ['motorway']
|
|
|
|
};
|
|
|
|
osrm.nearest(options, function(err, response) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(response.waypoints.length, 1);
|
|
|
|
});
|
|
|
|
});
|