2022-05-07 16:17:37 +02:00
|
|
|
import isRoughlyEqual from 'is-roughly-equal'
|
2018-10-29 22:11:08 +01:00
|
|
|
|
|
|
|
const testJourneysWalkingSpeed = async (cfg) => {
|
2020-05-21 22:21:07 +02:00
|
|
|
const {test: t, journeys, validate, from, to, when, products, minTimeDifference} = cfg
|
2018-10-29 22:11:08 +01:00
|
|
|
|
|
|
|
const {journeys: [journeyWithFastWalking]} = await journeys(from, to, {
|
2020-05-21 22:21:07 +02:00
|
|
|
departure: when,
|
2018-10-29 22:11:08 +01:00
|
|
|
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, {
|
2020-05-21 22:21:07 +02:00
|
|
|
departure: when,
|
2018-10-29 22:11:08 +01:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
testJourneysWalkingSpeed,
|
|
|
|
}
|