From 0c145d352bcc01acca5d8b4488a79a96e81c8e0e Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 29 Oct 2018 22:11:08 +0100 Subject: [PATCH] BVG, VBB: tests for walkingSpeed option :white_check_mark: --- test/bvg.js | 22 ++++++++++++++++++++++ test/cmta.js | 1 + test/db.js | 1 + test/lib/journeys-walking-speed.js | 29 +++++++++++++++++++++++++++++ test/sbahn-muenchen.js | 2 ++ test/vbb.js | 22 ++++++++++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 test/lib/journeys-walking-speed.js diff --git a/test/bvg.js b/test/bvg.js index ac53256d..ab3c74bc 100644 --- a/test/bvg.js +++ b/test/bvg.js @@ -26,6 +26,7 @@ const { const testJourneysStationToStation = require('./lib/journeys-station-to-station') const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') +const testJourneysWalkingSpeed = require('./lib/journeys-walking-speed') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testLegCycleAlternatives = require('./lib/leg-cycle-alternatives') const testRefreshJourney = require('./lib/refresh-journey') @@ -167,6 +168,27 @@ test('journeys – BerlKönig', async (t) => { t.end() }) +// todo: opt.walkingSpeed doesn't seem to work right now +test.skip('journeys: walkingSpeed', async (t) => { + const havelchaussee = { + type: 'location', + address: 'Havelchaussee', + latitude: 52.443576, + longitude: 13.198973 + } + const wannsee = '900000053301' + + await testJourneysWalkingSpeed({ + test: t, + journeys: client.journeys, + validate, + from: havelchaussee, + to: wannsee, + products: {bus: false}, + minTimeDifference: 5 * 60 * 1000 + }) +}) + test('earlier/later journeys', async (t) => { await testEarlierLaterJourneys({ test: t, diff --git a/test/cmta.js b/test/cmta.js index 003c7587..ce448781 100644 --- a/test/cmta.js +++ b/test/cmta.js @@ -119,6 +119,7 @@ test('Domain to Whole Foods Market - North Lamar Blvd', async (t) => { t.end() }) +// todo: walkingSpeed "2107 MELRIDGE PL" -> 000002148 // todo: via works – with detour // todo: without detour diff --git a/test/db.js b/test/db.js index 72d85202..ea927743 100644 --- a/test/db.js +++ b/test/db.js @@ -188,6 +188,7 @@ test('journeys: via works – with detour', async (t) => { t.end() }) +// todo: walkingSpeed "Berlin - Charlottenburg, Hallerstraße" -> jungfernheide // todo: without detour test('earlier/later journeys, Jungfernheide -> München Hbf', async (t) => { diff --git a/test/lib/journeys-walking-speed.js b/test/lib/journeys-walking-speed.js new file mode 100644 index 00000000..62e57c4f --- /dev/null +++ b/test/lib/journeys-walking-speed.js @@ -0,0 +1,29 @@ +'use strict' + +const isRoughlyEqual = require('is-roughly-equal') + +const testJourneysWalkingSpeed = async (cfg) => { + const {test: t, journeys, validate, from, to, products, minTimeDifference} = cfg + + const {journeys: [journeyWithFastWalking]} = await journeys(from, to, { + results: 1, products, walkingSpeed: 'fast' + }) + const legWithFastWalking = journeyWithFastWalking.legs.find(l => l.walking) + t.ok(legWithFastWalking, 'no walking leg in journey with fast walking') + + const {journeys: [journeyWithSlowWalking]} = await journeys(from, to, { + results: 1, products, walkingSpeed: 'slow' + }) + const legWithSlowWalking = journeyWithSlowWalking.legs.find(l => l.walking) + t.ok(legWithSlowWalking, 'no walking leg in journey with slow walking') + + const fastDist = legWithFastWalking.distance + const slowDist = legWithSlowWalking.distance + t.ok(isRoughlyEqual(100, fastDist, slowDist), 'precondition failed') + const fastDur = new Date(legWithFastWalking.arrival) - new Date(legWithFastWalking.departure) + const slowDur = new Date(legWithSlowWalking.arrival) - new Date(legWithSlowWalking.departure) + t.notOk(isRoughlyEqual(minTimeDifference, fastDur, slowDur), 'walkingSpeed not applied') + t.end() +} + +module.exports = testJourneysWalkingSpeed diff --git a/test/sbahn-muenchen.js b/test/sbahn-muenchen.js index 9c11376d..ff7852a2 100644 --- a/test/sbahn-muenchen.js +++ b/test/sbahn-muenchen.js @@ -55,6 +55,7 @@ const client = createClient(sMunichProfile, 'public-transport/hafas-client:test' const mittersendling = '8004154' const karlTheodorStr = '621790' // Karl-Theodor-Straße +const lehel = '000624826' const poetschnerstr = { type: 'location', address: 'Pötschnerstraße 3, Neuhausen', @@ -133,6 +134,7 @@ test('Karl-Theodor-Straße to Hofbräuhaus', async (t) => { t.end() }) +// todo: walkingSpeed "München - Freimann, Gyßlingstraße 78" -> lehel // todo: via works – with detour // todo: without detour diff --git a/test/vbb.js b/test/vbb.js index 4a525da2..5cb1db0b 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -18,6 +18,7 @@ const createValidate = require('./lib/validate-fptf-with') const testJourneysStationToStation = require('./lib/journeys-station-to-station') const testJourneysStationToAddress = require('./lib/journeys-station-to-address') const testJourneysStationToPoi = require('./lib/journeys-station-to-poi') +const testJourneysWalkingSpeed = require('./lib/journeys-walking-speed') const testEarlierLaterJourneys = require('./lib/earlier-later-journeys') const testRefreshJourney = require('./lib/refresh-journey') const journeysFailsWithNoProduct = require('./lib/journeys-fails-with-no-product') @@ -120,6 +121,27 @@ test('journeys – fails with no product', (t) => { t.end() }) +test('journeys: walkingSpeed', async (t) => { + const havelchaussee = { + type: 'location', + address: 'Havelchaussee', + latitude: 52.443576, + longitude: 13.198973 + } + const wannsee = '900000053301' + + await testJourneysWalkingSpeed({ + test: t, + journeys: client.journeys, + validate, + from: havelchaussee, + to: wannsee, + products: {bus: false}, + minTimeDifference: 5 * 60 * 1000 + }) + t.end() +}) + test('earlier/later journeys', async (t) => { await testEarlierLaterJourneys({ test: t,