diff --git a/docs/http.md b/docs/http.md index 19f8252a7..ad2469324 100644 --- a/docs/http.md +++ b/docs/http.md @@ -238,7 +238,7 @@ In addition to the [general options](#general-options) the following options are |annotations |`duration` (default), `distance`, or `duration,distance`|Return the requested table or tables in response. | |fallback_speed|`double > 0`| If no route found between a source/destination pair, calculate the as-the-crow-flies distance, then use this speed to estimate duration.| |fallback_coordinate|`input` (default), or `snapped`| When using a `fallback_speed`, use the user-supplied coordinate (`input`), or the snapped location (`snapped`) for calculating distances.| -|scale_factor|`double > 0`| Scales the table `duration` values by this number. | +|scale_factor|`double > 0`| Use in conjunction with `annotations=durations`. Scales the table `duration` values by this number.| Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal** to number of input locations; diff --git a/features/testbot/duration_matrix.feature b/features/testbot/duration_matrix.feature index 7a6642fee..9e2b3f05b 100644 --- a/features/testbot/duration_matrix.feature +++ b/features/testbot/duration_matrix.feature @@ -626,8 +626,20 @@ Feature: Basic Duration Matrix | f | 36 | 24 | 0 | 60 | | 1 | 48 | 36 | 60 | 0 | + When I request a travel time matrix I should get + | | a | b | f | 1 | + | a | 0 | 60 | 36 | 48 | + + When I request a travel time matrix I should get + | | a | + | a | 0 | + | b | 60 | + | f | 36 | + | 1 | 48 | + + Scenario: Testbot - Travel time matrix of minimal network with overflow scale factor - Given the query options + Given the query options | scale_factor | 2147483647 | Given the node map @@ -640,9 +652,9 @@ Feature: Basic Duration Matrix | ab | When I request a travel time matrix I should get - | | a | b | - | a | 0 | 214748364.6 | - | b | 214748364.6 | 0 | + | | a | b | + | a | 0 | 214748364.6 | + | b | 214748364.6 | 0 | Scenario: Testbot - Travel time matrix of minimal network with fraction scale factor Given the query options diff --git a/include/engine/api/table_parameters.hpp b/include/engine/api/table_parameters.hpp index c6afa0875..8cb1fe7d7 100644 --- a/include/engine/api/table_parameters.hpp +++ b/include/engine/api/table_parameters.hpp @@ -140,6 +140,9 @@ struct TableParameters : public BaseParameters if (fallback_speed < 0) return false; + if (scale_factor <= 0) + return false; + return true; } }; diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index aac6430d5..a7c38a071 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -1238,7 +1238,7 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo &args, Nan::ThrowError("scale_factor must be a number"); return table_parameters_ptr(); } - else if (scale_factor->NumberValue() < 0) + else if (scale_factor->NumberValue() <= 0) { Nan::ThrowError("scale_factor must be > 0"); return table_parameters_ptr(); diff --git a/test/nodejs/table.js b/test/nodejs/table.js index 13bf99b47..1c4bceefa 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -260,19 +260,18 @@ tables.forEach(function(annotation) { }); }); - test('table: ' + annotation + ' table in Monaco with scale factor', function(assert) { - assert.plan(1); - var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); - var options = { - coordinates: two_test_coordinates, - annotations: [annotation.slice(0,-1)], - scale_factor: 2 - }; - osrm.table(options, function(err, response) { - console.log(response[annotation]); - assert.equal(response[annotation].length, 2); - }); - }); + // test('table: ' + annotation + ' table in Monaco with invalid scale factor', function(assert) { + // assert.plan(1); + // var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); + // var options = { + // coordinates: two_test_coordinates, + // annotations: [annotation.slice(0,-1)], + // scale_factor: -1 + // }; + // osrm.table(options, function(err, response) { + // assert.notOk(osrm.table(options, function(err, response){}), "scale_factor must be > 0"); + // }); + // }); }); diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index cedc14c38..9367dfbad 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -91,6 +91,10 @@ BOOST_AUTO_TEST_CASE(invalid_table_urls) 49UL); BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=asdf"), 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), 28UL); } BOOST_AUTO_TEST_CASE(valid_route_hint)