source: josm/trunk/test/unit/org/openstreetmap/josm/corrector/ReverseWayTagCorrectorTest.java@ 11241

Last change on this file since 11241 was 11069, checked in by simon04, 8 years ago

fix #10260 - Do not switch (absolute) cardinal directions / degrees

  • Property svn:eol-style set to native
File size: 8.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.corrector;
3
4import java.util.Collections;
5import java.util.List;
6import java.util.Map;
7import java.util.stream.Stream;
8
9import org.junit.Assert;
10import org.junit.Rule;
11import org.junit.Test;
12import org.openstreetmap.josm.data.correction.TagCorrection;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.OsmUtils;
16import org.openstreetmap.josm.data.osm.Tag;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.testutils.JOSMTestRules;
19
20import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
21
22/**
23 * Unit tests of {@link ReverseWayTagCorrector} class.
24 */
25public class ReverseWayTagCorrectorTest {
26
27 /**
28 * Setup test.
29 */
30 @Rule
31 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
32 public JOSMTestRules test = new JOSMTestRules();
33
34 /**
35 * Test of {@link ReverseWayTagCorrector.TagSwitcher#apply} method.
36 */
37 @Test
38 public void testTagSwitch() {
39 // oneway
40 assertSwitch(new Tag("oneway", "yes"), new Tag("oneway", "-1"));
41 assertSwitch(new Tag("oneway", "true"), new Tag("oneway", "-1"));
42 assertSwitch(new Tag("oneway", "-1"), new Tag("oneway", "yes"));
43 assertSwitch(new Tag("oneway", "no"), new Tag("oneway", "no"));
44 assertSwitch(new Tag("oneway", "something"), new Tag("oneway", "something"));
45 // incline/direction
46 for (String k : new String[]{"incline", "direction"}) {
47 assertSwitch(new Tag(k, "up"), new Tag(k, "down"));
48 assertSwitch(new Tag(k, "down"), new Tag(k, "up"));
49 assertSwitch(new Tag(k, "something"), new Tag(k, "something"));
50 }
51 // direction=forward/backward/...
52 assertSwitch(new Tag("direction", "forward"), new Tag("direction", "backward"));
53 assertSwitch(new Tag("direction", "backward"), new Tag("direction", "forward"));
54 assertSwitch(new Tag("direction", "north"), new Tag("direction", "south"));
55 // :left/:right with oneway (see #10977)
56 assertSwitch(new Tag("cycleway:left:oneway", "-1"), new Tag("cycleway:right:oneway", "yes"));
57 // :forward/:backward (see #8518)
58 assertSwitch(new Tag("turn:forward", "right"), new Tag("turn:backward", "right"));
59 assertSwitch(new Tag("change:forward", "not_right"), new Tag("change:backward", "not_right"));
60 assertSwitch(new Tag("placement:forward", "right_of:1"), new Tag("placement:backward", "right_of:1"));
61 assertSwitch(new Tag("turn:lanes:forward", "left|right"), new Tag("turn:lanes:backward", "left|right"));
62 assertSwitch(new Tag("change:lanes:forward", "not_right|only_left"), new Tag("change:lanes:backward", "not_right|only_left"));
63 // keys
64 assertSwitch(new Tag("forward", "something"), new Tag("backward", "something"));
65 assertSwitch(new Tag("backward", "something"), new Tag("forward", "something"));
66 assertSwitch(new Tag("up", "something"), new Tag("down", "something"));
67 assertSwitch(new Tag("down", "something"), new Tag("up", "something"));
68 assertSwitch(new Tag("east", "something"), new Tag("west", "something"));
69 assertSwitch(new Tag("west", "something"), new Tag("east", "something"));
70 assertSwitch(new Tag("south", "something"), new Tag("north", "something"));
71 assertSwitch(new Tag("north", "something"), new Tag("south", "something"));
72 // values
73 assertSwitch(new Tag("something", "forward"), new Tag("something", "backward"));
74 assertSwitch(new Tag("something", "backward"), new Tag("something", "forward"));
75 assertSwitch(new Tag("something", "up"), new Tag("something", "down"));
76 assertSwitch(new Tag("something", "down"), new Tag("something", "up"));
77 assertSwitch(new Tag("something", "east"), new Tag("something", "west"));
78 assertSwitch(new Tag("something", "west"), new Tag("something", "east"));
79 assertSwitch(new Tag("something", "south"), new Tag("something", "north"));
80 assertSwitch(new Tag("something", "north"), new Tag("something", "south"));
81 // value[:_]suffix
82 assertSwitch(new Tag("something", "forward:suffix"), new Tag("something", "backward:suffix"));
83 assertSwitch(new Tag("something", "backward_suffix"), new Tag("something", "forward_suffix"));
84 assertSwitch(new Tag("something", "up:suffix"), new Tag("something", "down:suffix"));
85 assertSwitch(new Tag("something", "down_suffix"), new Tag("something", "up_suffix"));
86 assertSwitch(new Tag("something", "east:suffix"), new Tag("something", "west:suffix"));
87 assertSwitch(new Tag("something", "west_suffix"), new Tag("something", "east_suffix"));
88 assertSwitch(new Tag("something", "south:suffix"), new Tag("something", "north:suffix"));
89 assertSwitch(new Tag("something", "north_suffix"), new Tag("something", "south_suffix"));
90 // prefix[:_]value
91 assertSwitch(new Tag("something", "prefix:forward"), new Tag("something", "prefix:backward"));
92 assertSwitch(new Tag("something", "prefix_backward"), new Tag("something", "prefix_forward"));
93 assertSwitch(new Tag("something", "prefix:up"), new Tag("something", "prefix:down"));
94 assertSwitch(new Tag("something", "prefix_down"), new Tag("something", "prefix_up"));
95 assertSwitch(new Tag("something", "prefix:east"), new Tag("something", "prefix:west"));
96 assertSwitch(new Tag("something", "prefix_west"), new Tag("something", "prefix_east"));
97 assertSwitch(new Tag("something", "prefix:south"), new Tag("something", "prefix:north"));
98 assertSwitch(new Tag("something", "prefix_north"), new Tag("something", "prefix_south"));
99 // prefix[:_]value[:_]suffix
100 assertSwitch(new Tag("something", "prefix:forward:suffix"), new Tag("something", "prefix:backward:suffix"));
101 assertSwitch(new Tag("something", "prefix_backward:suffix"), new Tag("something", "prefix_forward:suffix"));
102 assertSwitch(new Tag("something", "prefix:up_suffix"), new Tag("something", "prefix:down_suffix"));
103 assertSwitch(new Tag("something", "prefix_down_suffix"), new Tag("something", "prefix_up_suffix"));
104 assertSwitch(new Tag("something", "prefix:east:suffix"), new Tag("something", "prefix:west:suffix"));
105 assertSwitch(new Tag("something", "prefix_west:suffix"), new Tag("something", "prefix_east:suffix"));
106 assertSwitch(new Tag("something", "prefix:south_suffix"), new Tag("something", "prefix:north_suffix"));
107 assertSwitch(new Tag("something", "prefix_north_suffix"), new Tag("something", "prefix_south_suffix"));
108 // #8499
109 assertSwitch(new Tag("type", "drawdown"), new Tag("type", "drawdown"));
110 }
111
112 private void assertSwitch(Tag oldTag, Tag newTag) {
113 Assert.assertEquals(ReverseWayTagCorrector.TagSwitcher.apply(oldTag), newTag);
114 }
115
116 private Map<OsmPrimitive, List<TagCorrection>> getTagCorrectionsForWay(String middleNodeTags) {
117 final OsmPrimitive n1 = OsmUtils.createPrimitive("node");
118 final OsmPrimitive n2 = OsmUtils.createPrimitive("node " + middleNodeTags);
119 final OsmPrimitive n3 = OsmUtils.createPrimitive("node");
120 final Way w = new Way();
121 Stream.of(n1, n2, n3).map(Node.class::cast).forEach(w::addNode);
122 return ReverseWayTagCorrector.getTagCorrectionsMap(w);
123 }
124
125 /**
126 * Test tag correction on way nodes
127 */
128 @Test
129 public void testSwitchingWayNodes() {
130 final Map<OsmPrimitive, List<TagCorrection>> tagCorrections = getTagCorrectionsForWay("direction=forward");
131 Assert.assertEquals(1, tagCorrections.size());
132 Assert.assertEquals(Collections.singletonList(new TagCorrection("direction", "forward", "direction", "backward")),
133 tagCorrections.values().iterator().next());
134 }
135
136 /**
137 * Test tag correction on way nodes are not applied for absolute values such as compass cardinal directions
138 */
139 @Test
140 public void testNotSwitchingWayNodes() {
141 Assert.assertEquals(0, getTagCorrectionsForWay("direction=SSW").size());
142 Assert.assertEquals(0, getTagCorrectionsForWay("direction=145").size());
143 }
144}
Note: See TracBrowser for help on using the repository browser.