From 3b00c22c4d8b4c2f4617c00d281dab8e1cd3236d Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Wed, 29 Mar 2017 15:28:45 +0200 Subject: [PATCH] NodeJS Binding Tests Does not run the nodejs tests in sanitized builds. We'd have to export LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libasan.so.2' the asan lib. But it seems like our Clang from mason does not like the system's libasan. Also we'd need a suppression file for v8 and node. --- .travis.yml | 4 + CMakeLists.txt | 2 + package.json | 4 +- src/nodejs/CMakeLists.txt | 4 +- test/nodejs/constants.js | 26 ++++++ test/nodejs/index.js | 16 ++-- test/nodejs/match.js | 63 +++++++------ test/nodejs/nearest.js | 21 +++-- test/nodejs/osrm-data-path.js | 12 --- test/nodejs/route.js | 171 +++++++++++++++++----------------- test/nodejs/table.js | 51 +++++----- test/nodejs/tile.js | 28 +++--- test/nodejs/trip.js | 106 ++++++++++----------- 13 files changed, 272 insertions(+), 236 deletions(-) create mode 100644 test/nodejs/constants.js delete mode 100644 test/nodejs/osrm-data-path.js diff --git a/.travis.yml b/.travis.yml index e82079c6357..b8437d961e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -223,6 +223,10 @@ script: - ./unit_tests/util-tests - ./unit_tests/server-tests - ./unit_tests/partition-tests + - | + if [ -n "${ENABLE_NODE_BINDINGS}" ] && [ -z "${ENABLE_SANITIZER}" ]; then + npm run nodejs-tests + fi - popd - yarn test diff --git a/CMakeLists.txt b/CMakeLists.txt index fe271ab80d5..341eb954b80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -303,6 +303,8 @@ endif() if (ENABLE_SANITIZER) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") set(OSRM_CXXFLAGS "${OSRM_CXXFLAGS} -fsanitize=address") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") endif() # Configuring compilers diff --git a/package.json b/package.json index 701681a0871..b3dd2041865 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld", "clean": "rm -rf test/cache", "docs": "./scripts/build_api_docs.sh", - "install": "node-pre-gyp install --fallback-to-build=false" + "install": "node-pre-gyp install --fallback-to-build=false", + "nodejs-tests": "make -C test/data && ./lib/binding/osrm-datastore test/data/ch/monaco.osrm && node test/nodejs/index.js | faucet" }, "repository": { "type": "git", @@ -44,6 +45,7 @@ "mkdirp": "^0.5.1", "aws-sdk": "~2.0.31", "tape": "^4.2.2", + "faucet": "^0.0.1", "node-timeout": "0.0.4", "polyline": "^0.2.0", "request": "^2.69.0", diff --git a/src/nodejs/CMakeLists.txt b/src/nodejs/CMakeLists.txt index fe39eee6c59..0ee094b2837 100644 --- a/src/nodejs/CMakeLists.txt +++ b/src/nodejs/CMakeLists.txt @@ -7,12 +7,14 @@ message(STATUS "Building node-osrm") set(BINDING_DIR "${PROJECT_SOURCE_DIR}/lib/binding") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/nodejs") -include(FindNodeJS) set(NodeJS_CXX_STANDARD 14 CACHE INTERNAL "Use C++14" FORCE) set(NodeJS_DOWNLOAD ON CACHE INTERNAL "Download node.js sources" FORCE) set(NodeJS_USE_CLANG_STDLIB OFF CACHE BOOL "Don't use libc++ by default" FORCE) +# ^ Make sure to set NodeJs options before including and requiring the NodeJs module. +# Otherwise the module will use defaults (which - among many bad choices - means libc++). +include(FindNodeJS) find_package(NodeJS REQUIRED) add_nodejs_module(node-osrm node_osrm.cpp) target_link_libraries(node-osrm osrm) diff --git a/test/nodejs/constants.js b/test/nodejs/constants.js new file mode 100644 index 00000000000..6459170535d --- /dev/null +++ b/test/nodejs/constants.js @@ -0,0 +1,26 @@ +var path = require('path'); + +// Constants and fixtures for nodejs tests on our Monaco dataset. + +// Somewhere in Monaco +// http://www.openstreetmap.org/#map=18/43.73185/7.41772 +exports.three_test_coordinates = [[7.41337, 43.72956], + [7.41546, 43.73077], + [7.41862, 43.73216]]; + +exports.two_test_coordinates = exports.three_test_coordinates.slice(0, 2) + +exports.test_tile = {'at': [17059, 11948, 15], 'size': 114000}; + + +// Test files generated by the routing engine; check test/data +if (process.env.OSRM_DATA_PATH !== undefined) { + exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/monaco.osrm"); + exports.mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/monaco.osrm"); + exports.corech_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "corech/monaco.osrm"); + console.log('Setting custom data path to ' + exports.data_path); +} else { + exports.data_path = path.resolve(path.join(__dirname, "../data/ch/monaco.osrm")); + exports.mld_data_path = path.resolve(path.join(__dirname, "../data/mld/monaco.osrm")); + exports.corech_data_path = path.resolve(path.join(__dirname, "../data/corech/monaco.osrm")); +} diff --git a/test/nodejs/index.js b/test/nodejs/index.js index 2ea1b859ceb..7c82e3a0545 100644 --- a/test/nodejs/index.js +++ b/test/nodejs/index.js @@ -1,8 +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; +var monaco_path = require('./constants').data_path; +var monaco_mld_path = require('./constants').mld_data_path; +var monaco_corech_path = require('./constants').corech_data_path; test('constructor: throws if new keyword is not used', function(assert) { assert.plan(1); @@ -30,7 +30,7 @@ test('constructor: throws if necessary files do not exist', function(assert) { test('constructor: takes a shared memory argument', function(assert) { assert.plan(1); - var osrm = new OSRM({path: berlin_path, shared_memory: false}); + var osrm = new OSRM({path: monaco_path, shared_memory: false}); assert.ok(osrm); }); @@ -42,7 +42,7 @@ test('constructor: throws if shared_memory==false with no path defined', functio test('constructor: throws if given a non-bool shared_memory option', function(assert) { assert.plan(1); - assert.throws(function() { new OSRM({path: berlin_path, shared_memory: 'a'}); }, + assert.throws(function() { new OSRM({path: monaco_path, shared_memory: 'a'}); }, /Shared_memory option must be a boolean/); }); @@ -66,19 +66,19 @@ test('constructor: throws if given an invalid algorithm', function(assert) { test('constructor: loads MLD if given as algorithm', function(assert) { assert.plan(1); - var osrm = new OSRM({algorithm: 'MLD', path: berlin_mld_path}); + var osrm = new OSRM({algorithm: 'MLD', path: monaco_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}); + var osrm = new OSRM({algorithm: 'CH', path: monaco_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}); + var osrm = new OSRM({algorithm: 'CoreCH', path: monaco_corech_path}); assert.ok(osrm); }); diff --git a/test/nodejs/match.js b/test/nodejs/match.js index 3a22f897463..088b3336524 100644 --- a/test/nodejs/match.js +++ b/test/nodejs/match.js @@ -1,12 +1,14 @@ var OSRM = require('../../'); var test = require('tape'); -var berlin_path = require('./osrm-data-path').data_path; +var data_path = require('./constants').data_path; +var three_test_coordinates = require('./constants').three_test_coordinates; +var two_test_coordinates = require('./constants').two_test_coordinates; -test('match: match in Berlin', function(assert) { +test('match: match in Monaco', function(assert) { assert.plan(5); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]], + coordinates: three_test_coordinates, timestamps: [1424684612, 1424684616, 1424684620] }; osrm.match(options, function(err, response) { @@ -22,11 +24,11 @@ test('match: match in Berlin', function(assert) { }); }); -test('match: match in Berlin without timestamps', function(assert) { +test('match: match in Monaco without timestamps', function(assert) { assert.plan(3); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]] + coordinates: three_test_coordinates }; osrm.match(options, function(err, response) { assert.ifError(err); @@ -35,11 +37,11 @@ test('match: match in Berlin without timestamps', function(assert) { }); }); -test('match: match in Berlin without geometry compression', function(assert) { +test('match: match in Monaco without geometry compression', function(assert) { assert.plan(4); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]], + coordinates: three_test_coordinates, geometries: 'geojson' }; osrm.match(options, function(err, response) { @@ -50,11 +52,11 @@ test('match: match in Berlin without geometry compression', function(assert) { }); }); -test('match: match in Berlin with geometry compression', function(assert) { +test('match: match in Monaco with geometry compression', function(assert) { assert.plan(3); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]] + coordinates: three_test_coordinates, }; osrm.match(options, function(err, response) { assert.ifError(err); @@ -63,11 +65,11 @@ test('match: match in Berlin with geometry compression', function(assert) { }); }); -test('match: match in Berlin with speed annotations options', function(assert) { +test('match: match in Monaco with speed annotations options', function(assert) { assert.plan(12); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]], + coordinates: three_test_coordinates, timestamps: [1424684612, 1424684616, 1424684620], radiuses: [4.07, 4.07, 4.07], steps: true, @@ -92,11 +94,12 @@ test('match: match in Berlin with speed annotations options', function(assert) { }); -test('match: match in Berlin with several (duration, distance, nodes) annotations options', function(assert) { +test('match: match in Monaco with several (duration, distance, nodes) annotations options', function(assert) { assert.plan(12); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]], + timestamps: [1424684612, 1424684616, 1424684620], + coordinates: three_test_coordinates, timestamps: [1424684612, 1424684616, 1424684620], radiuses: [4.07, 4.07, 4.07], steps: true, @@ -120,11 +123,11 @@ test('match: match in Berlin with several (duration, distance, nodes) annotation }); }); -test('match: match in Berlin with all options', function(assert) { +test('match: match in Monaco with all options', function(assert) { assert.plan(8); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]], + coordinates: three_test_coordinates, timestamps: [1424684612, 1424684616, 1424684620], radiuses: [4.07, 4.07, 4.07], steps: true, @@ -146,42 +149,42 @@ test('match: match in Berlin with all options', function(assert) { test('match: throws on missing arguments', function(assert) { assert.plan(1); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_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); + var osrm = new OSRM(data_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 osrm = new OSRM(data_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]]; + options.coordinates = [three_test_coordinates[0]]; assert.throws(function() { osrm.match(options, function(err, response) {}) }, /At least two coordinates must be provided/); - options.coordinates = [13.393252,52.542648]; + options.coordinates = three_test_coordinates[0] assert.throws(function() { osrm.match(options, function(err, response) {}) }, /Coordinates must be an array of \(lon\/lat\) pairs/); - options.coordinates = [[13.393252],[52.542648]]; + options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]]; 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 osrm = new OSRM(data_path); var options = { - coordinates: [[13.393252,52.542648],[13.39478,52.543079],[13.397389,52.542107]], + coordinates: three_test_coordinates, timestamps: 'timestamps' }; assert.throws(function() { osrm.match(options, function(err, response) {}) }, diff --git a/test/nodejs/nearest.js b/test/nodejs/nearest.js index d4197b1e127..69835f90da2 100644 --- a/test/nodejs/nearest.js +++ b/test/nodejs/nearest.js @@ -1,12 +1,15 @@ var OSRM = require('../../'); var test = require('tape'); -var berlin_path = require('./osrm-data-path').data_path; +var data_path = require('./constants').data_path; +var three_test_coordinates = require('./constants').three_test_coordinates; +var two_test_coordinates = require('./constants').two_test_coordinates; + test('nearest', function(assert) { assert.plan(4); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); osrm.nearest({ - coordinates: [[13.333086, 52.4224]] + coordinates: [three_test_coordinates[0]] }, function(err, result) { assert.ifError(err); assert.equal(result.waypoints.length, 1); @@ -17,9 +20,9 @@ test('nearest', function(assert) { test('nearest: can ask for multiple nearest pts', function(assert) { assert.plan(2); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); osrm.nearest({ - coordinates: [[13.333086, 52.4224]], + coordinates: [three_test_coordinates[0]], number: 3 }, function(err, result) { assert.ifError(err); @@ -29,19 +32,19 @@ test('nearest: can ask for multiple nearest pts', function(assert) { test('nearest: throws on invalid args', function(assert) { assert.plan(6); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_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]; + options.coordinates = [43.73072]; 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]]; + options.coordinates = [three_test_coordinates[0], three_test_coordinates[1]]; assert.throws(function() { osrm.nearest(options, function(err, res) {}); }, /Exactly one coordinate pair must be provided/); - options.coordinates = [[13.333086, 52.4224]]; + options.coordinates = [three_test_coordinates[0]]; options.number = 3.14159; assert.throws(function() { osrm.nearest(options, function(err, res) {}); }, /Number must be an integer greater than or equal to 1/); diff --git a/test/nodejs/osrm-data-path.js b/test/nodejs/osrm-data-path.js deleted file mode 100644 index d443e8e8a36..00000000000 --- a/test/nodejs/osrm-data-path.js +++ /dev/null @@ -1,12 +0,0 @@ -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")); -} diff --git a/test/nodejs/route.js b/test/nodejs/route.js index 8cc26f57cd8..d3705ecaa68 100644 --- a/test/nodejs/route.js +++ b/test/nodejs/route.js @@ -1,13 +1,16 @@ 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; +var monaco_path = require('./constants').data_path; +var monaco_mld_path = require('./constants').mld_data_path; +var monaco_corech_path = require('./constants').corech_data_path; +var three_test_coordinates = require('./constants').three_test_coordinates; +var two_test_coordinates = require('./constants').two_test_coordinates; -test('route: routes Berlin', function(assert) { + +test('route: routes Monaco', 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) { + var osrm = new OSRM(monaco_path); + osrm.route({coordinates: two_test_coordinates}, function(err, route) { assert.ifError(err); assert.ok(route.waypoints); assert.ok(route.routes); @@ -16,9 +19,9 @@ test('route: routes Berlin', function(assert) { }); }); -test('route: routes Berlin on MLD', function(assert) { +test('route: routes Monaco on MLD', function(assert) { assert.plan(5); - var osrm = new OSRM({path: berlin_mld_path, algorithm: 'MLD'}); + var osrm = new OSRM({path: monaco_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); @@ -28,9 +31,9 @@ test('route: routes Berlin on MLD', function(assert) { }); }); -test('route: routes Berlin on CoreCH', function(assert) { +test('route: routes Monaco on CoreCH', function(assert) { assert.plan(5); - var osrm = new OSRM({path: berlin_corech_path, algorithm: 'CoreCH'}); + var osrm = new OSRM({path: monaco_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); @@ -42,19 +45,19 @@ test('route: routes Berlin on CoreCH', function(assert) { 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]]}) }, + var osrm = new OSRM(monaco_path); + assert.throws(function() { osrm.route({coordinates: two_test_coordinates}) }, /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)}, + assert.throws(function() { osrm.route({coordinates: two_test_coordinates}, true)}, /last argument must be a callback function/); }); -test('route: provides no alternatives by default, but when requested', function(assert) { +test('route: provides no alternatives by default, but when requested it may (not guaranteed)', function(assert) { assert.plan(6); - var osrm = new OSRM(berlin_path); - var options = {coordinates: [[13.302383,52.490516], [13.418427,52.522070]]}; + var osrm = new OSRM(monaco_path); + var options = {coordinates: two_test_coordinates}; osrm.route(options, function(err, route) { assert.ifError(err); @@ -65,53 +68,53 @@ test('route: provides no alternatives by default, but when requested', function( osrm.route(options, function(err, route) { assert.ifError(err); assert.ok(route.routes); - assert.equal(route.routes.length, 2); + assert.ok(route.routes.length >= 1); }); }); test('route: throws with bad params', function(assert) { assert.plan(11); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_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) {}) }, + assert.throws(function() { osrm.route({coordinates: [[three_test_coordinates[0]], [three_test_coordinates[1]]]}, 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) {}) }, + assert.throws(function() { osrm.route({coordinates: [[true, 'stringish'], three_test_coordinates[1]]}, 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) {}) }, + assert.throws(function() { osrm.route({coordinates: two_test_coordinates, 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) {}) }); + assert.throws(function() { osrm.route({coordinates: two_test_coordinates, steps: null}, function(err, route) {}) }); + assert.throws(function() { osrm.route({coordinates: two_test_coordinates, annotations: null}, function(err, route) {}) }); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, alternateRoute: false, - hints: [13.438640, 52.519930] + hints: three_test_coordinates[0] }; assert.throws(function() { osrm.route(options, function(err, route) {}) }, /Hint must be null or string/); }); -test('route: routes Berlin using shared memory', function(assert) { +test('route: routes Monaco 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) { + osrm.route({coordinates: two_test_coordinates}, function(err, route) { assert.ifError(err); assert.ok(Array.isArray(route.routes)); }); }); -test('route: routes Berlin with geometry compression', function(assert) { +test('route: routes Monaco with geometry compression', function(assert) { assert.plan(2); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, }; osrm.route(options, function(err, route) { assert.ifError(err); @@ -119,11 +122,11 @@ test('route: routes Berlin with geometry compression', function(assert) { }); }); -test('route: routes Berlin without geometry compression', function(assert) { +test('route: routes Monaco without geometry compression', function(assert) { assert.plan(4); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, geometries: 'geojson' }; osrm.route(options, function(err, route) { @@ -136,9 +139,9 @@ test('route: routes Berlin without geometry compression', function(assert) { test('Test polyline6 geometries option', function(assert) { assert.plan(6); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, continue_straight: false, overview: 'false', geometries: 'polyline6', @@ -154,11 +157,11 @@ test('Test polyline6 geometries option', function(assert) { }); }); -test('route: routes Berlin with speed annotations options', function(assert) { +test('route: routes Monaco with speed annotations options', function(assert) { assert.plan(17); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, continue_straight: false, overview: 'false', geometries: 'polyline', @@ -193,16 +196,16 @@ test('route: routes Berlin with speed annotations options', function(assert) { }); }); -test('route: routes Berlin with several (duration, distance, nodes) annotations options', function(assert) { +test('route: routes Monaco with several (duration, distance, nodes) annotations options', function(assert) { assert.plan(17); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, continue_straight: false, overview: 'false', geometries: 'polyline', steps: true, - annotations: ['duration','distance','nodes'] + annotations: ['duration', 'distance', 'nodes'] }; osrm.route(options, function(err, first) { assert.ifError(err); @@ -232,11 +235,11 @@ test('route: routes Berlin with several (duration, distance, nodes) annotations }); }); -test('route: routes Berlin with options', function(assert) { +test('route: routes Monaco with options', function(assert) { assert.plan(11); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, continue_straight: false, overview: 'false', geometries: 'polyline', @@ -265,11 +268,11 @@ test('route: routes Berlin with options', function(assert) { }); }); -test('route: routes Berlin with options', function(assert) { +test('route: routes Monaco with options', function(assert) { assert.plan(11); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, continue_straight: false, overview: 'false', geometries: 'polyline', @@ -300,39 +303,39 @@ test('route: routes Berlin with options', function(assert) { test('route: invalid route options', function(assert) { assert.plan(8); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, continue_straight: [] }, function(err, route) {}); }, /must be boolean/); assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, alternatives: [] }, function(err, route) {}); }, /must be boolean/); assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, geometries: 'maybe' }, function(err, route) {}); }, /'geometries' param must be one of \[polyline, polyline6, geojson\]/); @@ -344,9 +347,9 @@ test('route: invalid route options', function(assert) { test('route: integer bearing values no longer supported', function(assert) { assert.plan(1); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, bearings: [200, 250], }; assert.throws(function() { osrm.route(options, function(err, route) {}); }, @@ -355,9 +358,9 @@ test('route: integer bearing values no longer supported', function(assert) { test('route: valid bearing values', function(assert) { assert.plan(4); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, bearings: [[200, 180], [250, 180]], }; osrm.route(options, function(err, route) { @@ -373,44 +376,44 @@ test('route: valid bearing values', function(assert) { test('route: invalid bearing values', function(assert) { assert.plan(6); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, bearings: [Infinity, Infinity], }, function(err, route) {}) }, /Bearing must be an array of \[bearing, range\] or null/); }); -test('route: routes Berlin with hints', function(assert) { +test('route: routes Monaco with hints', function(assert) { assert.plan(5); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]] + coordinates: two_test_coordinates, }; osrm.route(options, function(err, first) { assert.ifError(err); @@ -427,11 +430,11 @@ test('route: routes Berlin with hints', function(assert) { }); }); -test('route: routes Berlin with null hints', function(assert) { +test('route: routes Monaco with null hints', function(assert) { assert.plan(1); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, hints: [null, null] }; osrm.route(options, function(err, route) { @@ -441,22 +444,22 @@ test('route: routes Berlin with null hints', function(assert) { test('route: throws on bad hints', function(assert) { assert.plan(2); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, hints: ['', ''] }, function(err, route) {})}, /Hint cannot be an empty string/); assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, 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) { +test('route: routes Monaco with valid radius values', function(assert) { assert.plan(3); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, radiuses: [100, 100] }; osrm.route(options, function(err, route) { @@ -474,23 +477,23 @@ test('route: routes Berlin with valid radius values', function(assert) { test('route: throws on bad radiuses', function(assert) { assert.plan(3); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(monaco_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, radiuses: [10, 10] }; assert.throws(function() { osrm.route({ - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, 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]], + coordinates: two_test_coordinates, radiuses: [10] }, function(err, route) {}) }, /Radiuses array must have the same length as coordinates array/); diff --git a/test/nodejs/table.js b/test/nodejs/table.js index a1b05365c7c..7535998434b 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -1,12 +1,15 @@ var OSRM = require('../../'); var test = require('tape'); -var berlin_path = require('./osrm-data-path').data_path; +var data_path = require('./constants').data_path; +var three_test_coordinates = require('./constants').three_test_coordinates; +var two_test_coordinates = require('./constants').two_test_coordinates; -test('table: distance table in Berlin', function(assert) { - assert.plan(9); - var osrm = new OSRM(berlin_path); + +test('table: distance table in Monaco', function(assert) { + assert.plan(11); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]] + coordinates: [three_test_coordinates[0], three_test_coordinates[1]] }; osrm.table(options, function(err, table) { assert.ifError(err); @@ -23,6 +26,8 @@ test('table: distance table in Berlin', function(assert) { } else { // everything else is non-zero assert.notEqual(0, column[j], 'other entries must be non-zero'); + // and finite (not nan, inf etc.) + assert.ok(Number.isFinite(column[j]), 'distance is finite number'); } } } @@ -30,11 +35,11 @@ test('table: distance table in Berlin', function(assert) { }); }); -test('table: distance table in Berlin with sources/destinations', function(assert) { - assert.plan(6); - var osrm = new OSRM(berlin_path); +test('table: distance table in Monaco with sources/destinations', function(assert) { + assert.plan(7); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], sources: [0], destinations: [0,1] }; @@ -53,6 +58,8 @@ test('table: distance table in Berlin with sources/destinations', function(asser } else { // everything else is non-zero assert.notEqual(0, column[j], 'other entries must be non-zero'); + // and finite (not nan, inf etc.) + assert.ok(Number.isFinite(column[j]), 'distance is finite number'); } } } @@ -62,24 +69,24 @@ test('table: distance table in Berlin with sources/destinations', function(asser test('table: throws on invalid arguments', function(assert) { assert.plan(14); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_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]]; + options.coordinates = [three_test_coordinates[0]]; assert.throws(function() { osrm.table(options, function(err, response) {}) }, /At least two coordinates must be provided/); - options.coordinates = [13.393252,52.542648]; + options.coordinates = three_test_coordinates[0]; assert.throws(function() { osrm.table(options, function(err, response) {}) }, /Coordinates must be an array of \(lon\/lat\) pairs/); - options.coordinates = [[13.393252],[52.542648]]; + options.coordinates = [three_test_coordinates[0][0], three_test_coordinates[0][1]]; 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.coordinates = two_test_coordinates; options.sources = true; assert.throws(function() { osrm.table(options, function(err, response) {}) }, /Sources must be an array of indices \(or undefined\)/); @@ -110,22 +117,22 @@ test('table: throws on invalid arguments', function(assert) { 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) {}) }, + assert.throws(function() { osrm.route({coordinates: two_test_coordinates, 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); + var osrm = new OSRM(data_path); assert.throws(function() { osrm.table(null, function() {}); }, /First arg must be an object/); }); -test('table: distance table in Berlin with hints', function(assert) { +test('table: distance table in Monaco with hints', function(assert) { assert.plan(5); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, generate_hints: true // true is default but be explicit here }; osrm.table(options, function(err, table) { @@ -141,11 +148,11 @@ test('table: distance table in Berlin with hints', function(assert) { }); }); -test('table: distance table in Berlin without hints', function(assert) { +test('table: distance table in Monaco without hints', function(assert) { assert.plan(5); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, generate_hints: false // true is default }; osrm.table(options, function(err, table) { diff --git a/test/nodejs/tile.js b/test/nodejs/tile.js index a273df63ec2..f76da5867dd 100644 --- a/test/nodejs/tile.js +++ b/test/nodejs/tile.js @@ -1,23 +1,25 @@ var OSRM = require('../../'); var test = require('tape'); -var berlin_path = "test/data/berlin-latest.osrm"; +var data_path = require('./constants').data_path; +var tile = require('./constants').test_tile; 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) { + var osrm = new OSRM(data_path); + osrm.tile(tile.at, function(err, result) { assert.ifError(err); - assert.ok(result.length > 35000); + assert.ok(result.length > tile.size); }); }); -// 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); - }); +test.test('tile interface pre-conditions', function(assert) { + assert.plan(6); + var osrm = new OSRM(data_path); + + assert.throws(function() { osrm.tile(null, function(err, result) {}) }, /must be an array \[x, y, z\]/); + assert.throws(function() { osrm.tile([], function(err, result) {}) }, /must be an array \[x, y, z\]/); + assert.throws(function() { osrm.tile([[]], function(err, result) {}) }, /must be an array \[x, y, z\]/); + assert.throws(function() { osrm.tile(undefined, function(err, result) {}) }, /must be an array \[x, y, z\]/); + assert.throws(function() { osrm.tile(17059, 11948, 15, function(err, result) {}) }, /must be an array \[x, y, z\]/); + assert.throws(function() { osrm.tile([17059, 11948, -15], function(err, result) {}) }, /must be unsigned/); }); diff --git a/test/nodejs/trip.js b/test/nodejs/trip.js index 52b62031fc4..b506426d62a 100644 --- a/test/nodejs/trip.js +++ b/test/nodejs/trip.js @@ -1,11 +1,14 @@ var OSRM = require('../../'); var test = require('tape'); -var berlin_path = require('./osrm-data-path').data_path; +var data_path = require('./constants').data_path; +var three_test_coordinates = require('./constants').three_test_coordinates; +var two_test_coordinates = require('./constants').two_test_coordinates; -test('trip: trip in Berlin', function(assert) { + +test('trip: trip in Monaco', 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) { + var osrm = new OSRM(data_path); + osrm.trip({coordinates: two_test_coordinates}, function(err, trip) { assert.ifError(err); for (t = 0; t < trip.trips.length; t++) { assert.ok(trip.trips[t].geometry); @@ -13,28 +16,25 @@ test('trip: trip in Berlin', function(assert) { }); }); -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]] -}; +test('trip: trip with many locations in Monaco', function(assert) { + assert.plan(2); + + var many = 5; + + var osrm = new OSRM(data_path); + var opts = {coordinates: three_test_coordinates.slice(0, many)}; 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]]}) }, + var osrm = new OSRM(data_path); + assert.throws(function() { osrm.trip({coordinates: two_test_coordinates}) }, /Two arguments required/); assert.throws(function() { osrm.trip(null, function(err, trip) {}) }, /First arg must be an object/); @@ -42,7 +42,7 @@ test('trip: throws with too few or invalid args', function(assert) { test('trip: throws with bad params', function(assert) { assert.plan(14); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); assert.throws(function () { osrm.trip({coordinates: []}, function(err) {}) }); assert.throws(function() { osrm.trip({}, function(err, trip) {}) }, /Must provide a coordinates property/); @@ -51,22 +51,21 @@ test('trip: throws with bad params', function(assert) { }, function(err, trip) {}) }, /Coordinates must be an array of \(lon\/lat\) pairs/); assert.throws(function() { osrm.trip({ - coordinates: [13.438640, 52.519930] + coordinates: three_test_coordinates[0] }, function(err, trip) {}) }, /Coordinates must be an array of \(lon\/lat\) pairs/); assert.throws(function() { osrm.trip({ - coordinates: [[13.438640], [52.519930]] + coordinates: [three_test_coordinates[0][0], three_test_coordinates[0][1]] }, 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]], + coordinates: two_test_coordinates, 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] + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], + hints: three_test_coordinates[0] }; assert.throws(function() { osrm.trip(options, function(err, trip) {}); }, /Hint must be null or string/); @@ -96,10 +95,10 @@ test('trip: throws with bad params', function(assert) { /'roundtrip' param must be a boolean/); }); -test('trip: routes Berlin using shared memory', function(assert) { +test('trip: routes Monaco 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) { + osrm.trip({coordinates: two_test_coordinates}, function(err, trip) { assert.ifError(err); for (t = 0; t < trip.trips.length; t++) { assert.ok(trip.trips[t].geometry); @@ -107,11 +106,11 @@ test('trip: routes Berlin using shared memory', function(assert) { }); }); -test('trip: routes Berlin with hints', function(assert) { +test('trip: routes Monaco with hints', function(assert) { assert.plan(5); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, steps: false }; osrm.trip(options, function(err, first) { @@ -130,11 +129,11 @@ test('trip: routes Berlin with hints', function(assert) { }); }); -test('trip: trip through Berlin with geometry compression', function(assert) { +test('trip: trip through Monaco with geometry compression', function(assert) { assert.plan(2); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]] + coordinates: [three_test_coordinates[0], three_test_coordinates[1]] }; osrm.trip(options, function(err, trip) { assert.ifError(err); @@ -144,11 +143,11 @@ test('trip: trip through Berlin with geometry compression', function(assert) { }); }); -test('trip: trip through Berlin without geometry compression', function(assert) { +test('trip: trip through Monaco without geometry compression', function(assert) { assert.plan(2); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, geometries: 'geojson' }; osrm.trip(options, function(err, trip) { @@ -159,11 +158,11 @@ test('trip: trip through Berlin without geometry compression', function(assert) }); }); -test('trip: trip through Berlin with speed annotations options', function(assert) { +test('trip: trip through Monaco with speed annotations options', function(assert) { assert.plan(12); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, steps: true, annotations: ['speed'], overview: 'false' @@ -186,11 +185,11 @@ test('trip: trip through Berlin with speed annotations options', function(assert }); }); -test('trip: trip through Berlin with several (duration, distance, nodes) annotations options', function(assert) { +test('trip: trip through Monaco with several (duration, distance, nodes) annotations options', function(assert) { assert.plan(12); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, steps: true, annotations: ['duration', 'distance', 'nodes'], overview: 'false' @@ -213,11 +212,11 @@ test('trip: trip through Berlin with several (duration, distance, nodes) annotat }); }); -test('trip: trip through Berlin with options', function(assert) { +test('trip: trip through Monaco with options', function(assert) { assert.plan(6); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, steps: true, annotations: true, overview: 'false' @@ -234,12 +233,11 @@ test('trip: trip through Berlin with options', function(assert) { }); }); -test('trip: routes Berlin with null hints', function(assert) { +test('trip: routes Monaco with null hints', function(assert) { assert.plan(1); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], - printInstructions: false, + coordinates: [three_test_coordinates[0], three_test_coordinates[1]], hints: [null, null] }; osrm.trip(options, function(err, second) { @@ -249,11 +247,11 @@ test('trip: routes Berlin with null hints', function(assert) { test('trip: service combinations that are not implemented', function(assert) { assert.plan(3); - var osrm = new OSRM(berlin_path); + var osrm = new OSRM(data_path); // fixed start, non-roundtrip var options = { - coordinates: [[13.43864,52.51993],[13.415852,52.513191]], + coordinates: two_test_coordinates, source: 'first', roundtrip: false }; @@ -278,10 +276,10 @@ test('trip: service combinations that are not implemented', function(assert) { }); test('trip: fixed start and end combinations', function(assert) { - var osrm = new OSRM(berlin_path); - + var osrm = new OSRM(data_path); + var options = { - coordinates: [[13.36761474609375,52.51663871100423],[13.374481201171875,52.506191342034576]], + coordinates: two_test_coordinates, source: 'first', destination: 'last', roundtrip: false, @@ -291,10 +289,8 @@ test('trip: fixed start and end combinations', function(assert) { // 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])); }); @@ -304,9 +300,7 @@ test('trip: fixed start and end combinations', function(assert) { 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])); }); }