BVG, VBB: tests for walkingSpeed option

This commit is contained in:
Jannis R 2018-10-29 22:11:08 +01:00
parent 9c47a3908c
commit 0c145d352b
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
6 changed files with 77 additions and 0 deletions

View file

@ -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,

View file

@ -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

View file

@ -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) => {

View file

@ -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

View file

@ -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

View file

@ -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,