-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
61 lines (55 loc) · 1.51 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const test = require('tape')
const fs = require('fs')
const path = require('path')
const {parse} = require('ndjson')
const stations = require('vbb-stations/full.json')
const read = (file) => {
return fs.createReadStream(path.join(__dirname, file))
.pipe(parse())
}
const isValidProduct = (p) => {
return p === 'suburban'
|| p === 'subway'
|| p === 'regional'
|| p === 'tram'
|| p === 'bus'
}
test('nodes.ndjson', (t) => {
read('nodes.ndjson')
.on('error', t.ifError)
.on('data', (node) => {
t.equal(typeof node.id, 'string')
t.ok(stations[node.id], 'invalid station id ' + node.id)
t.equal(typeof node.label, 'string')
t.ok(node.metadata, 'missing metadata')
if ('number' === typeof node.metadata.x) {
t.equal(typeof node.metadata.y, 'number')
} else {
t.equal(typeof node.metadata.latitude, 'number')
t.equal(typeof node.metadata.longitude, 'number')
}
})
.on('end', () => t.end())
})
test('edges.ndjson', (t) => {
const isKnownStation = {}
read('nodes.ndjson')
.on('error', t.ifError)
.on('data', (node) => {
isKnownStation[node.id] = true
})
.on('end', () => {
read('edges.ndjson')
.on('error', t.ifError)
.on('data', (edge) => {
t.ok(isKnownStation[edge.source], 'invalid source id')
t.ok(isKnownStation[edge.target], 'invalid target id')
t.ok(isValidProduct(edge.relation), 'invalid product')
t.ok(edge.metadata, 'missing metadata')
t.ok(typeof edge.metadata.line, 'string')
t.ok(typeof edge.metadata.time, 'number')
})
.on('end', () => t.end())
})
})