-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
171 lines (145 loc) · 4.72 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import test from 'tape'
import {isStream} from 'is-stream'
import isRoughlyEqual from 'is-roughly-equal'
import {parseRil100} from './build/parse.js'
import {
readStations as stations,
readFullStations as fullStations,
} from './index.js'
import {createFilter} from './create-filter.js'
const assertIsValidStation = (t, s, row) => {
t.equal(s.type, 'station', `row ${row}: s.type`)
t.equal(typeof s.id, 'string', `row ${row}: s.id`)
t.ok(s.id, `row ${row}: s.id`)
if (s.nr !== null) t.equal(typeof s.nr, 'number', `row ${row}: s.nr`)
if (s.ril100 !== null) {
t.equal(typeof s.ril100, 'string', `row ${row}: s.ril100`)
t.ok(s.ril100, `row ${row}: s.ril100`)
}
t.equal(typeof s.name, 'string', `row ${row}: s.name`)
t.ok(s.name, `row ${row}: s.name`)
if (s.weight !== undefined && s.weight !== null) {
t.equal(typeof s.weight, 'number', `row ${row}: s.weight`)
t.ok(s.weight > 0, `row ${row}: s.weight`)
}
if (s.address) {
if (s.address.street) {
t.equal(typeof s.address.street, 'string', `row ${row}: s.address.street`)
t.ok(s.address.street, `row ${row}: s.address.street`)
}
if (s.address.zipcode) {
t.equal(typeof s.address.zipcode, 'string', `row ${row}: s.address.zipcode`)
t.ok(s.address.zipcode, `row ${row}: s.address.zipcode`)
}
if (s.address.city) {
t.equal(typeof s.address.city, 'string', `row ${row}: s.address.city`)
t.ok(s.address.city, `row ${row}: s.address.city`)
}
}
if (s.location !== null) {
t.equal(s.location.type, 'location', `row ${row}: s.location.type`)
t.equal(typeof s.location.latitude, 'number', `row ${row}: s.location.latitude`)
t.ok(isRoughlyEqual(5, s.location.latitude, 51), `row ${row}: s.location.latitude`)
t.equal(typeof s.location.longitude, 'number', `row ${row}: s.location.longitude`)
t.ok(isRoughlyEqual(5, s.location.longitude, 10), `row ${row}: s.location.longitude`)
}
}
const assertIsJungfernheide = (t, s) => {
t.ok(s.id === '8089100' || s.id === '8011167', 'id is 8089100 or 8011167')
t.equal(s.nr, 3067)
t.ok(s.ril100 === 'BJUF' || s.ril100 === 'BJUN') // WAT
t.equal(s.name, 'Jungfernheide')
t.equal(s.address.zipcode, '10589')
t.equal(s.address.city, 'Berlin')
t.ok(isRoughlyEqual(.0001, s.location.latitude, 52.530276))
t.ok(isRoughlyEqual(.0001, s.location.longitude, 13.299437))
}
test('parseRil100 works', (t) => {
const adelschlag = {
number: 12,
name: 'Adelschlag',
evaNumbers: [{
isMain: true,
number: 8000419,
geographicCoordinates: {latitude: 1.23, longitude: 2.34},
}],
ril100Identifiers: [{
isMain: true,
rilIdentifier: 'MAD',
hasSteamPermission: true,
geographicCoordinates: {latitude: 2.34, longitude: 1.23},
}],
}
t.equal(parseRil100(adelschlag), 'MAD')
t.end()
})
test('data.ndjson contains valid simplified stations', (t) => {
let row = 0
stations()
.on('error', t.ifError)
.on('data', (s) => {
assertIsValidStation(t, s, ++row)
})
.on('end', () => {
t.end()
})
})
test('data.ndjson contains Berlin Jungfernheide', (t) => {
stations()
.on('error', t.ifError)
.on('data', (s) => {
if (s.id === '8089100' || s.id === '8011167') {
assertIsJungfernheide(t, s)
t.end()
}
})
})
test('full.ndjson contains valid full stations', (t) => {
fullStations()
.on('error', t.ifError)
.on('data', (s) => {
assertIsValidStation(t, s)
t.ok(Array.isArray(s.additionalIds))
t.notOk(s.additionalIds.includes(s.operator.id))
t.ok(s.operator)
t.equal(s.operator.type, 'operator')
t.equal(typeof s.operator.id, 'string')
t.ok(s.operator.id)
t.equal(typeof s.operator.name, 'string')
t.ok(s.operator.name)
if (s.category) t.equal(typeof s.category, 'number')
if (s.federalState) t.equal(typeof s.federalState, 'string')
if ('hasParking' in s) t.equal(typeof s.hasParking, 'boolean')
if ('hasBicycleParking' in s) t.equal(typeof s.hasBicycleParking, 'boolean')
if ('hasLocalPublicTransport' in s) t.equal(typeof s.hasLocalPublicTransport, 'boolean')
if ('hasPublicFacilities' in s) t.equal(typeof s.hasPublicFacilities, 'boolean')
if ('hasLockerSystem' in s) t.equal(typeof s.hasLockerSystem, 'boolean')
if ('hasTaxiRank' in s) t.equal(typeof s.hasTaxiRank, 'boolean')
})
.on('end', () => {
t.end()
})
})
test('full.ndjson contains Berlin Jungfernheide', (t) => {
fullStations()
.on('error', t.ifError)
.on('data', (s) => {
if (s.id === '8089100' || s.id === '8011167') {
assertIsJungfernheide(t, s)
t.end()
}
})
})
test('createFilter works properly', (t) => {
const s = {
type: 'station',
id: 'foo',
name: 'Foo',
location: {latitude: 1.23, longitude: 2.34}
}
t.equal(createFilter({id: 'foo'})(s), true)
t.equal(createFilter({id: 'FOO'})(s), false)
t.equal(createFilter({latitude: 1.24})(s), false)
t.equal(createFilter({latitude: 1.24})(s), false)
t.end()
})