cucumber: enable checking mode in routability tables (#3748)

* cucumber: enable checking mode in routability tables

* show actual mode when expected was none

* minor fixes
This commit is contained in:
Emil Tin
2017-03-07 09:56:19 +01:00
committed by Daniel J. H
parent 65669f23a1
commit ee076e6156
7 changed files with 337 additions and 343 deletions
+15 -5
View File
@@ -10,7 +10,7 @@ module.exports = function () {
headers = new Set(Object.keys(table.hashes()[0]));
if (!testedHeaders.some(k => !!headers.has(k))) {
throw new Error('*** routability table must contain either "forw", "backw", "bothw", "forw_rate" or "backw_rate" column');
throw new Error('*** routability table must contain either "forw", "backw", "bothw", "forw_rate" or "backw_mode" column');
}
this.reprocessAndLoadData((e) => {
@@ -62,9 +62,12 @@ module.exports = function () {
// rename forw/backw to forw/backw_speed
switch (true) {
case '' === want:
outputRow[direction] = result[direction].status ?
result[direction].mode : '';
break;
case 'x' === want:
outputRow[direction] = result[direction].status ?
result[direction].status.toString() : '';
'x' : '';
break;
case /^[\d\.]+ s/.test(want):
// the result here can come back as a non-number value like
@@ -88,7 +91,7 @@ module.exports = function () {
}
break;
default:
throw new Error(util.format('*** Unknown expectation format: %s', want));
outputRow[direction] = result[direction].mode || '';
}
if (this.FuzzyMatch.match(outputRow[direction], want)) {
@@ -106,7 +109,7 @@ module.exports = function () {
// makes simple a-b request using the given cucumber test routability conditions
// result is an object containing the calculated values for 'rate', 'status',
// 'time', 'distance', and 'speed' for forwards and backwards routing, as well as
// 'time', 'distance', 'speed' and 'mode', for forwards and backwards routing, as well as
// a bothw object that diffs forwards/backwards
var testRoutabilityRow = (i, cb) => {
var result = {};
@@ -133,6 +136,13 @@ module.exports = function () {
r.distance = r.json.routes[0].distance;
r.rate = Math.round(r.distance / r.json.routes[0].weight);
r.speed = r.time > 0 ? parseInt(3.6 * r.distance / r.time) : null;
// use the mode of the first step of the route
// for routability table test, we can assume the mode is the same throughout the route,
// since the route is just a single way
if( r.json.routes[0].legs[0] && r.json.routes[0].legs[0].steps[0] ) {
r.mode = r.json.routes[0].legs[0].steps[0].mode;
}
} else {
r.status = null;
}
@@ -167,7 +177,7 @@ module.exports = function () {
scb();
};
['rate', 'status', 'time', 'distance', 'speed'].forEach((key) => {
['rate', 'status', 'time', 'distance', 'speed' ,'mode'].forEach((key) => {
sq.defer(parseRes, key);
});