-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
33 lines (27 loc) · 910 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {createClient as createHafas} from 'hafas-client'
import {profile as dbProfile} from 'hafas-client/p/db/index.js'
import * as assert from 'assert'
import {createWalkAndDiscoverStations as createWalk} from './index.js'
const hafas = createHafas(dbProfile, 'hafas-discover-stations test')
const walk = createWalk(hafas)
const berlinFriedrichstr = '8011306'
const data = walk(berlinFriedrichstr)
data.on('error', err => {
console.error(err)
process.exit(1)
})
let stations = 0
const knownStations = Object.create(null)
const onData = (stop) => {
assert.ok(stop)
assert.ok(stop.type === 'stop' || stop.type === 'station')
if (knownStations[stop.id]) assert.fail(stop.id + ' occured twice')
knownStations[stop.id] = true
stations++
if (stations >= 200) {
data.removeListener('data', onData)
data.stop()
console.info(`Discovered ${stations} stations. ✔︎`)
}
}
data.on('data', onData)