Skip to content

Commit 6b357a7

Browse files
danpatPatrick Niklaus
authored andcommitted
Test cases for route relation cardinal directions.
1 parent fc9a89e commit 6b357a7

File tree

4 files changed

+234
-49
lines changed

4 files changed

+234
-49
lines changed

features/car/route_relations.feature

Lines changed: 207 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,230 @@ Feature: Car - route relations
33
Background:
44
Given the profile "car"
55

6-
@sliproads
7-
Scenario: Cardinal direction assignment to refs
6+
Scenario: Assignment using relation membership roles
87
Given the node map
98
"""
10-
a b
11-
| |
12-
c------+--+------d
13-
e------+--+------f
14-
| |
15-
g h
9+
a----------------b
10+
c----------------d
11+
"""
1612

17-
i----------------j
18-
k----------------l
13+
And the ways
14+
| nodes | name | highway | ref |
15+
| ba | westbound | motorway | I 80 |
16+
| cd | eastbound | motorway | I 80;CO 93 |
1917

20-
x----------------y
21-
z----------------w
18+
And the relations
19+
| type | way:east | way:west | route | ref | network |
20+
| route | cd | ba | road | 80 | US:I |
21+
| route | cd | ba | road | 93 | US:CO |
22+
23+
24+
When I route I should get
25+
| waypoints | route | ref |
26+
| b,a | westbound,westbound | I 80 $west,I 80 $west |
27+
| c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
28+
29+
Scenario: Assignment using relation direction property (no role on members)
30+
Given the node map
31+
"""
32+
a----------------b
33+
c----------------d
2234
"""
2335

2436
And the ways
2537
| nodes | name | highway | ref |
26-
| ag | southbound | motorway | I 80 |
27-
| hb | northbound | motorway | I 80 |
28-
| dc | westbound | motorway | I 85;CO 93 |
29-
| ef | eastbound | motorway | I 85;US 12 |
30-
| ij | westbound-2 | motorway | I 99 |
31-
| ji | eastbound-2 | motorway | I 99 |
32-
| kl | eastbound-2 | motorway | I 99 |
33-
| lk | eastbound-2 | motorway | I 99 |
34-
| xy | watermill | motorway | I 45M; US 3 |
38+
| ba | westbound | motorway | I 80 |
39+
| cd | eastbound | motorway | I 80;CO 93 |
3540

3641
And the relations
37-
| type | way:south | route | ref |
38-
| route | ag | road | 80 |
39-
| route | ef | road | 12 |
42+
| type | direction | way | route | ref | network |
43+
| route | west | ba | road | 80 | US:I |
44+
| route | east | cd | road | 80 | US:I |
45+
| route | east | cd | road | 93 | US:CO |
46+
47+
When I route I should get
48+
| waypoints | route | ref |
49+
| b,a | westbound,westbound | I 80 $west,I 80 $west |
50+
| c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
51+
52+
53+
Scenario: Forward assignment on one-way roads using relation direction property
54+
Given the node map
55+
"""
56+
a----------------b
57+
c----------------d
58+
"""
59+
60+
And the ways
61+
| nodes | name | highway | ref |
62+
| ba | westbound | motorway | I 80 |
63+
| cd | eastbound | motorway | I 80;CO 93 |
4064

4165
And the relations
42-
| type | way:north | route | ref |
43-
| route | hb | road | 80 |
44-
| route | cd | road | 93 |
66+
| type | direction | way:forward | route | ref | network |
67+
| route | west | ba | road | 80 | US:I |
68+
| route | east | cd | road | 80 | US:I |
69+
| route | east | cd | road | 93 | US:CO |
70+
71+
When I route I should get
72+
| waypoints | route | ref |
73+
| b,a | westbound,westbound | I 80 $west,I 80 $west |
74+
| c,d | eastbound,eastbound | I 80 $east; CO 93 $east,I 80 $east; CO 93 $east |
75+
76+
77+
Scenario: Forward/backward assignment on non-divided roads with role direction tag
78+
Given the node map
79+
"""
80+
a----------------b
81+
"""
82+
83+
And the ways
84+
| nodes | name | highway | ref | oneway |
85+
| ab | mainroad | motorway | I 80 | no |
86+
87+
And the relations
88+
| type | direction | way:forward | route | ref | network |
89+
| route | west | ab | road | 80 | US:I |
90+
91+
And the relations
92+
| type | direction | way:backward | route | ref | network |
93+
| route | east | ab | road | 80 | US:I |
94+
95+
When I route I should get
96+
| waypoints | route | ref |
97+
| b,a | mainroad,mainroad | I 80 $west,I 80 $west |
98+
| a,b | mainroad,mainroad | I 80 $east,I 80 $east |
99+
100+
101+
Scenario: Conflict between role and direction
102+
Given the node map
103+
"""
104+
a----------------b
105+
"""
106+
107+
And the ways
108+
| nodes | name | highway | ref |
109+
| ab | eastbound | motorway | I 80 |
110+
111+
And the relations
112+
| type | direction | way:east | route | ref | network |
113+
| route | west | ab | road | 80 | US:I |
114+
115+
When I route I should get
116+
| waypoints | route | ref |
117+
| a,b | eastbound,eastbound | I 80,I 80 |
118+
119+
120+
Scenario: Conflict between role and superrelation direction
121+
Given the node map
122+
"""
123+
a----------------b
124+
"""
125+
126+
And the ways
127+
| nodes | name | highway | ref |
128+
| ab | eastbound | motorway | I 80 |
129+
130+
And the relations
131+
| type | way:east | route | ref | network | name |
132+
| route | ab | road | 80 | US:I | baserelation |
133+
134+
And the relations
135+
| type | direction | relation | route | ref | network | name |
136+
| route | east | baserelation | road | 80 | US:I | superrelation |
137+
138+
When I route I should get
139+
| waypoints | route | ref |
140+
| a,b | eastbound,eastbound | I 80,I 80 |
141+
142+
Scenario: Conflict between role and superrelation role
143+
Given the node map
144+
"""
145+
a----------------b
146+
"""
147+
148+
And the ways
149+
| nodes | name | highway | ref |
150+
| ab | eastbound | motorway | I 80 |
151+
152+
And the relations
153+
| type | way:east | route | ref | network | name |
154+
| route | ab | road | 80 | US:I | baserelation |
155+
156+
And the relations
157+
| type | relation:west | route | ref | network | name |
158+
| route | baserelation | road | 80 | US:I | superrelation |
159+
160+
When I route I should get
161+
| waypoints | route | ref |
162+
| a,b | eastbound,eastbound | I 80,I 80 |
163+
164+
Scenario: Direction only available via superrelation role
165+
Given the node map
166+
"""
167+
a----------------b
168+
"""
169+
170+
And the ways
171+
| nodes | name | highway | ref |
172+
| ab | eastbound | motorway | I 80 |
173+
174+
And the relations
175+
| type | way:forward | route | ref | network | name |
176+
| route | ab | road | 80 | US:I | baserelation |
177+
178+
And the relations
179+
| type | relation:east | route | ref | network | name |
180+
| route | baserelation | road | 80 | US:I | superrelation |
181+
182+
When I route I should get
183+
| waypoints | route | ref |
184+
| a,b | eastbound,eastbound | I 80 $east,I 80 $east |
185+
186+
Scenario: Direction only available via superrelation direction
187+
Given the node map
188+
"""
189+
a----------------b
190+
"""
191+
192+
And the ways
193+
| nodes | name | highway | ref |
194+
| ab | eastbound | motorway | I 80 |
195+
196+
And the relations
197+
| type | way:forward | route | ref | network | name |
198+
| route | ab | road | 80 | US:I | baserelation |
199+
200+
And the relations
201+
| type | direction | relation | route | ref | network | name |
202+
| route | east | baserelation | road | 80 | US:I | superrelation |
203+
204+
When I route I should get
205+
| waypoints | route | ref |
206+
| a,b | eastbound,eastbound | I 80 $east,I 80 $east |
207+
208+
Scenario: Three levels of indirection
209+
Given the node map
210+
"""
211+
a----------------b
212+
"""
213+
214+
And the ways
215+
| nodes | name | highway | ref |
216+
| ab | eastbound | motorway | I 80 |
45217

46218
And the relations
47-
| type | way:west | route | ref |
48-
| route | dc | road | 85 |
49-
| route | ij | road | 99 |
50-
| route | xy | road | I 45 |
219+
| type | way:forward | route | ref | network | name |
220+
| route | ab | road | 80 | US:I | baserelation |
51221

52222
And the relations
53-
| type | way:east | route | ref |
54-
| route | lk | road | I 99 |
223+
| type | relation | route | ref | network | name |
224+
| route | baserelation | road | 80 | US:I | superrelation1 |
55225

56226
And the relations
57-
| type | way:east | route | ref |
58-
| route | xy | road | US 3 |
227+
| type | direction | relation | route | ref | network | name |
228+
| route | east | superrelation1 | road | 80 | US:I | superrelation2 |
59229

60230
When I route I should get
61-
| waypoints | route | ref |
62-
| a,g | southbound,southbound | I 80 $south,I 80 $south |
63-
| h,b | northbound,northbound | I 80 $north,I 80 $north |
64-
| d,c | westbound,westbound | I 85 $west; CO 93 $north,I 85 $west; CO 93 $north |
65-
| e,f | eastbound,eastbound | I 85; US 12 $south,I 85; US 12 $south |
66-
| i,j | westbound-2,westbound-2 | I 99 $west,I 99 $west |
67-
| l,k | eastbound-2,eastbound-2 | I 99 $east,I 99 $east |
68-
| x,y | watermill,watermill | I 45M $west; US 3 $east,I 45M $west; US 3 $east |
231+
| waypoints | route | ref |
232+
| a,b | eastbound,eastbound | I 80 $east,I 80 $east |

features/lib/osm.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ class DB {
8686
});
8787

8888
r.members.forEach((m) => {
89-
relation.ele('member', {
89+
var d = {
9090
type: m.type,
91-
ref: m.id,
92-
role: m.role
93-
});
91+
ref: m.id
92+
};
93+
if (m.role) d.role = m.role;
94+
relation.ele('member', d);
9495
});
9596

9697
for (var k in r.tags) {

features/step_definitions/data.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,12 @@ module.exports = function () {
188188
let addRelation = (row, cb) => {
189189
let relation = new OSM.Relation(this.makeOSMId(), this.OSM_USER, this.OSM_TIMESTAMP, this.OSM_UID);
190190

191+
192+
var name = null;
191193
for (let key in row) {
192-
let isNode = key.match(/^node:(.*)/),
193-
isWay = key.match(/^way:(.*)/),
194+
let isNode = key.match(/^node:?(.*)/),
195+
isWay = key.match(/^way:?(.*)/),
196+
isRelation = key.match(/^relation:?(.*)/),
194197
isColonSeparated = key.match(/^(.*):(.*)/);
195198
if (isNode) {
196199
row[key].split(',').map(function(v) { return v.trim(); }).forEach((nodeName) => {
@@ -205,14 +208,26 @@ module.exports = function () {
205208
if (!way) throw new Error(util.format('*** unknown relation way member "%s"', wayName));
206209
relation.addMember('way', way.id, isWay[1]);
207210
});
211+
} else if (isRelation) {
212+
row[key].split(',').map(function(v) { return v.trim(); }).forEach((relName) => {
213+
let otherrelation = this.findRelationByName(relName);
214+
if (!otherrelation) throw new Error(util.format('*** unknown relation relation member "%s"', relName));
215+
relation.addMember('relation', otherrelation.id, isRelation[1]);
216+
});
208217
} else if (isColonSeparated && isColonSeparated[1] !== 'restriction') {
209218
throw new Error(util.format('*** unknown relation member type "%s:%s", must be either "node" or "way"', isColonSeparated[1], isColonSeparated[2]));
210219
} else {
211220
relation.addTag(key, row[key]);
221+
if (key.match(/name/)) name = row[key];
212222
}
213223
}
214224
relation.uid = this.OSM_UID;
215225

226+
227+
if (name) {
228+
this.nameRelationHash[name] = relation;
229+
}
230+
216231
this.OSMDB.addRelation(relation);
217232

218233
cb();

features/support/data.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ module.exports = function () {
144144
return this.nameWayHash[s.toString()] || this.nameWayHash[s.toString().split('').reverse().join('')];
145145
};
146146

147+
this.findRelationByName = (s) => {
148+
return this.nameRelationHash[s.toString()] || this.nameRelationHash[s.toString().split('').reverse().join('')];
149+
};
150+
147151
this.makeOSMId = () => {
148152
this.osmID = this.osmID + 1;
149153
return this.osmID;
@@ -155,6 +159,7 @@ module.exports = function () {
155159
this.locationHash = {};
156160
this.shortcutsHash = {};
157161
this.nameWayHash = {};
162+
this.nameRelationHash = {};
158163
this.osmID = 0;
159164
};
160165

0 commit comments

Comments
 (0)