2017-03-01 12:27:57 -05:00
var OSRM = require ( '../../' ) ;
var test = require ( 'tape' ) ;
2017-03-29 09:28:45 -04:00
var monaco _path = require ( './constants' ) . data _path ;
2018-02-13 10:36:19 -05:00
var test _memory _file = require ( './constants' ) . test _memory _file ;
2017-03-29 09:28:45 -04:00
var monaco _mld _path = require ( './constants' ) . mld _data _path ;
var monaco _corech _path = require ( './constants' ) . corech _data _path ;
2017-03-01 12:27:57 -05:00
test ( 'constructor: throws if new keyword is not used' , function ( assert ) {
assert . plan ( 1 ) ;
assert . throws ( function ( ) { OSRM ( ) ; } ,
2022-11-16 09:44:36 -05:00
/Class constructors cannot be invoked without 'new'/ ) ;
2017-03-01 12:27:57 -05:00
} ) ;
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 ) {
2017-06-05 18:58:50 -04:00
assert . plan ( 2 ) ;
assert . throws ( function ( ) { new OSRM ( 'missing.osrm' ) ; } ,
/Required files are missing, cannot continue/ ) ;
assert . throws ( function ( ) { new OSRM ( { path : 'missing.osrm' , algorithm : 'MLD' } ) ; } ,
/Required files are missing, cannot continue/ ) ;
2017-03-01 12:27:57 -05:00
} ) ;
test ( 'constructor: takes a shared memory argument' , function ( assert ) {
assert . plan ( 1 ) ;
2017-03-29 09:28:45 -04:00
var osrm = new OSRM ( { path : monaco _path , shared _memory : false } ) ;
2017-03-01 12:27:57 -05:00
assert . ok ( osrm ) ;
} ) ;
2018-02-13 10:36:19 -05:00
test ( 'constructor: takes a memory file' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( { path : monaco _path , memory _file : test _memory _file } ) ;
assert . ok ( osrm ) ;
} ) ;
2017-03-01 12:27:57 -05:00
test ( 'constructor: throws if shared_memory==false with no path defined' , function ( assert ) {
assert . plan ( 1 ) ;
2017-03-17 11:19:56 -04:00
assert . throws ( function ( ) { new OSRM ( { shared _memory : false } ) ; } ,
2017-03-01 12:27:57 -05:00
/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 ) ;
2017-03-29 09:28:45 -04:00
assert . throws ( function ( ) { new OSRM ( { path : monaco _path , shared _memory : 'a' } ) ; } ,
2017-03-01 12:27:57 -05:00
/Shared_memory option must be a boolean/ ) ;
} ) ;
test ( 'constructor: throws if given a non-string/obj argument' , function ( assert ) {
assert . plan ( 1 ) ;
2017-03-17 11:19:56 -04:00
assert . throws ( function ( ) { new OSRM ( true ) ; } ,
2017-03-01 12:27:57 -05:00
/Parameter must be a path or options object/ ) ;
} ) ;
2017-03-17 11:19:56 -04:00
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 ) ;
2017-03-29 09:28:45 -04:00
var osrm = new OSRM ( { algorithm : 'MLD' , path : monaco _mld _path } ) ;
2017-03-17 11:19:56 -04:00
assert . ok ( osrm ) ;
} ) ;
test ( 'constructor: loads CH if given as algorithm' , function ( assert ) {
assert . plan ( 1 ) ;
2017-03-29 09:28:45 -04:00
var osrm = new OSRM ( { algorithm : 'CH' , path : monaco _path } ) ;
2017-03-17 11:19:56 -04:00
assert . ok ( osrm ) ;
} ) ;
test ( 'constructor: loads CoreCH if given as algorithm' , function ( assert ) {
assert . plan ( 1 ) ;
2017-03-29 09:28:45 -04:00
var osrm = new OSRM ( { algorithm : 'CoreCH' , path : monaco _corech _path } ) ;
2017-03-17 11:19:56 -04:00
assert . ok ( osrm ) ;
} ) ;
2017-06-05 18:58:50 -04:00
test ( 'constructor: autoswitches to CoreCH for a CH dataset if capable' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( { algorithm : 'CH' , path : monaco _corech _path } ) ;
assert . ok ( osrm ) ;
} ) ;
test ( 'constructor: throws if data doesn\'t match algorithm' , function ( assert ) {
assert . plan ( 3 ) ;
2018-04-04 10:05:46 -04:00
assert . throws ( function ( ) { new OSRM ( { algorithm : 'CoreCH' , path : monaco _mld _path } ) ; } , /Could not find any metrics for CH/ , 'CoreCH with MLD data' ) ;
assert . ok ( new OSRM ( { algorithm : 'CoreCH' , path : monaco _path } ) , 'CoreCH with CH data' ) ;
assert . throws ( function ( ) { new OSRM ( { algorithm : 'MLD' , path : monaco _path } ) ; } , /Could not find any metrics for MLD/ , 'MLD with CH data' ) ;
} ) ;
test ( 'constructor: throws if dataset_name is not a string' , function ( assert ) {
assert . plan ( 3 ) ;
assert . throws ( function ( ) { new OSRM ( { dataset _name : 1337 , path : monaco _mld _path } ) ; } , /dataset_name needs to be a string/ , 'Does not accept int' ) ;
assert . ok ( new OSRM ( { dataset _name : "" , shared _memory : true } ) , 'Does accept string' ) ;
assert . throws ( function ( ) { new OSRM ( { dataset _name : "unsued_name___" , shared _memory : true } ) ; } , /Could not find shared memory region/ , 'Does not accept wrong name' ) ;
2017-06-05 18:58:50 -04:00
} ) ;
2023-03-24 11:49:33 -04:00
test ( 'constructor: takes a default_radius argument' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( { algorithm : 'MLD' , path : monaco _mld _path , default _radius : 1 } ) ;
assert . ok ( osrm ) ;
} ) ;
2023-05-31 01:52:35 -04:00
test ( 'constructor: takes a default_radius unlimited argument' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( { algorithm : 'MLD' , path : monaco _mld _path , default _radius : 'unlimited' } ) ;
assert . ok ( osrm ) ;
} ) ;
2023-03-24 11:49:33 -04:00
test ( 'constructor: throws if default_radius is not a number' , function ( assert ) {
2023-05-31 01:52:35 -04:00
assert . plan ( 3 ) ;
assert . throws ( function ( ) { new OSRM ( { algorithm : 'MLD' , path : monaco _mld _path , default _radius : 'abc' } ) ; } , /default_radius must be unlimited or an integral number/ , 'Does not accept invalid string' ) ;
2023-03-24 11:49:33 -04:00
assert . ok ( new OSRM ( { algorithm : 'MLD' , path : monaco _mld _path , default _radius : 1 } ) , 'Does accept number' ) ;
2023-05-31 01:52:35 -04:00
assert . ok ( new OSRM ( { algorithm : 'MLD' , path : monaco _mld _path , default _radius : 'unlimited' } ) , 'Does accept unlimited' ) ;
2023-03-24 11:49:33 -04:00
} ) ;
2017-07-13 06:55:18 -04:00
test ( 'constructor: parses custom limits' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( {
path : monaco _mld _path ,
algorithm : 'MLD' ,
max _locations _trip : 1 ,
max _locations _viaroute : 1 ,
max _locations _distance _table : 1 ,
max _locations _map _matching : 1 ,
max _results _nearest : 1 ,
max _alternatives : 1 ,
2023-05-31 01:52:35 -04:00
default _radius : 1
2017-07-13 06:55:18 -04:00
} ) ;
assert . ok ( osrm ) ;
} ) ;
test ( 'constructor: throws on invalid custom limits' , function ( assert ) {
assert . plan ( 1 ) ;
assert . throws ( function ( ) {
var osrm = new OSRM ( {
path : monaco _mld _path ,
algorithm : 'MLD' ,
max _locations _trip : 'unlimited' ,
max _locations _viaroute : true ,
max _locations _distance _table : false ,
max _locations _map _matching : 'a lot' ,
max _results _nearest : null ,
2023-05-31 01:52:35 -04:00
max _alternatives : '10' ,
default _radius : '10'
2017-07-13 06:55:18 -04:00
} )
} ) ;
} ) ;
2023-08-04 13:43:37 -04:00
test ( 'constructor: throws on invalid disable_feature_dataset option' , function ( assert ) {
assert . plan ( 1 ) ;
assert . throws ( function ( ) {
var osrm = new OSRM ( {
path : monaco _path ,
disable _feature _dataset : [ 'NOT_EXIST' ] ,
} )
} ) ;
} ) ;
test ( 'constructor: throws on non-array disable_feature_dataset' , function ( assert ) {
assert . plan ( 1 ) ;
assert . throws ( function ( ) {
var osrm = new OSRM ( {
path : monaco _path ,
disable _feature _dataset : 'ROUTE_GEOMETRY' ,
} )
} ) ;
} ) ;
test ( 'constructor: ok on valid disable_feature_dataset option' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( {
path : monaco _path ,
disable _feature _dataset : [ 'ROUTE_GEOMETRY' ] ,
} ) ;
assert . ok ( osrm ) ;
} ) ;
test ( 'constructor: ok on multiple overlapping disable_feature_dataset options' , function ( assert ) {
assert . plan ( 1 ) ;
var osrm = new OSRM ( {
path : monaco _path ,
disable _feature _dataset : [ 'ROUTE_GEOMETRY' , 'ROUTE_STEPS' ] ,
} ) ;
assert . ok ( osrm ) ;
} ) ;
2017-07-13 06:55:18 -04:00
2017-03-01 12:27:57 -05:00
require ( './route.js' ) ;
require ( './trip.js' ) ;
require ( './match.js' ) ;
require ( './tile.js' ) ;
require ( './table.js' ) ;
require ( './nearest.js' ) ;