enforce clamping on < 0 and increase test coverage
This commit is contained in:
parent
8873d5b902
commit
742bf216ff
@ -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. |
|
|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_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.|
|
|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**
|
Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal**
|
||||||
to number of input locations;
|
to number of input locations;
|
||||||
|
|||||||
@ -626,6 +626,18 @@ Feature: Basic Duration Matrix
|
|||||||
| f | 36 | 24 | 0 | 60 |
|
| f | 36 | 24 | 0 | 60 |
|
||||||
| 1 | 48 | 36 | 60 | 0 |
|
| 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
|
Scenario: Testbot - Travel time matrix of minimal network with overflow scale factor
|
||||||
Given the query options
|
Given the query options
|
||||||
| scale_factor | 2147483647 |
|
| scale_factor | 2147483647 |
|
||||||
|
|||||||
@ -140,6 +140,9 @@ struct TableParameters : public BaseParameters
|
|||||||
if (fallback_speed < 0)
|
if (fallback_speed < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (scale_factor <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1238,7 +1238,7 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
|
|||||||
Nan::ThrowError("scale_factor must be a number");
|
Nan::ThrowError("scale_factor must be a number");
|
||||||
return table_parameters_ptr();
|
return table_parameters_ptr();
|
||||||
}
|
}
|
||||||
else if (scale_factor->NumberValue() < 0)
|
else if (scale_factor->NumberValue() <= 0)
|
||||||
{
|
{
|
||||||
Nan::ThrowError("scale_factor must be > 0");
|
Nan::ThrowError("scale_factor must be > 0");
|
||||||
return table_parameters_ptr();
|
return table_parameters_ptr();
|
||||||
|
|||||||
@ -260,19 +260,18 @@ tables.forEach(function(annotation) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('table: ' + annotation + ' table in Monaco with scale factor', function(assert) {
|
// test('table: ' + annotation + ' table in Monaco with invalid scale factor', function(assert) {
|
||||||
assert.plan(1);
|
// assert.plan(1);
|
||||||
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
// var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
||||||
var options = {
|
// var options = {
|
||||||
coordinates: two_test_coordinates,
|
// coordinates: two_test_coordinates,
|
||||||
annotations: [annotation.slice(0,-1)],
|
// annotations: [annotation.slice(0,-1)],
|
||||||
scale_factor: 2
|
// scale_factor: -1
|
||||||
};
|
// };
|
||||||
osrm.table(options, function(err, response) {
|
// osrm.table(options, function(err, response) {
|
||||||
console.log(response[annotation]);
|
// assert.notOk(osrm.table(options, function(err, response){}), "scale_factor must be > 0");
|
||||||
assert.equal(response[annotation].length, 2);
|
// });
|
||||||
});
|
// });
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -91,6 +91,10 @@ BOOST_AUTO_TEST_CASE(invalid_table_urls)
|
|||||||
49UL);
|
49UL);
|
||||||
BOOST_CHECK_EQUAL(testInvalidOptions<TableParameters>("1,2;3,4?fallback_coordinate=asdf"),
|
BOOST_CHECK_EQUAL(testInvalidOptions<TableParameters>("1,2;3,4?fallback_coordinate=asdf"),
|
||||||
28UL);
|
28UL);
|
||||||
|
BOOST_CHECK_EQUAL(
|
||||||
|
testInvalidOptions<TableParameters>("1,2;3,4?annotations=durations&scale_factor=-1"), 28UL);
|
||||||
|
BOOST_CHECK_EQUAL(
|
||||||
|
testInvalidOptions<TableParameters>("1,2;3,4?annotations=durations&scale_factor=0"), 28UL);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(valid_route_hint)
|
BOOST_AUTO_TEST_CASE(valid_route_hint)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user