Changeset 15076 in josm for trunk/test/unit
- Timestamp:
- 2019-05-15T22:28:07+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java
r15034 r15076 8 8 import java.util.ArrayList; 9 9 import java.util.Arrays; 10 import java.util.Collections; 11 import java.util.HashSet; 10 12 import java.util.List; 11 13 … … 15 17 import org.junit.Test; 16 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.Node; 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 21 import org.openstreetmap.josm.data.osm.Relation; 22 import org.openstreetmap.josm.data.osm.Way; 18 23 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 19 24 import org.openstreetmap.josm.io.IllegalDataException; … … 131 136 Assert.assertEquals("[BACKWARD, BACKWARD, BACKWARD, FPH FORWARD, FPH FORWARD, FPH FORWARD, FPH FORWARD]", actual); 132 137 } 138 139 private void reverseWay(Way way) { 140 List<Node> nodes = way.getNodes(); 141 Collections.reverse(nodes); 142 way.removeNodes(new HashSet<>(nodes)); 143 for (Node node : nodes) { 144 way.addNode(node); 145 } 146 } 147 148 /** 149 * Test directional {@link WayConnectionTypeCalculator#computeNextWayConnection} 150 */ 151 @Test 152 public void testDirectionsOnewaysOnly() { 153 Relation relation = getRelation("direction"); 154 155 // Check with only one wrong oneway 156 List<WayConnectionType> returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 157 for (int i = 0; i < 4; i++) { 158 Assert.assertTrue(returned.get(i).onewayFollowsPrevious); 159 Assert.assertTrue(returned.get(i).onewayFollowsNext); 160 } 161 162 Assert.assertTrue(returned.get(4).onewayFollowsPrevious); 163 Assert.assertFalse(returned.get(4).onewayFollowsNext); 164 165 Assert.assertFalse(returned.get(5).onewayFollowsPrevious); 166 Assert.assertFalse(returned.get(5).onewayFollowsNext); 167 168 Assert.assertFalse(returned.get(6).onewayFollowsPrevious); 169 Assert.assertTrue(returned.get(6).onewayFollowsNext); 170 171 // Reverse the last oneway 172 OsmPrimitive way7 = relation.getMemberPrimitivesList().get(6); 173 if (way7 instanceof Way) { 174 Way way = (Way) way7; 175 reverseWay(way); 176 returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 177 for (int i = 0; i < 4; i++) { 178 Assert.assertTrue(returned.get(i).onewayFollowsPrevious); 179 Assert.assertTrue(returned.get(i).onewayFollowsNext); 180 } 181 182 Assert.assertTrue(returned.get(4).onewayFollowsPrevious); 183 Assert.assertFalse(returned.get(4).onewayFollowsNext); 184 185 Assert.assertFalse(returned.get(5).onewayFollowsPrevious); 186 Assert.assertTrue(returned.get(5).onewayFollowsNext); 187 188 Assert.assertTrue(returned.get(6).onewayFollowsPrevious); 189 Assert.assertTrue(returned.get(6).onewayFollowsNext); 190 reverseWay(way); 191 } 192 193 // Reverse the wrong oneway 194 OsmPrimitive way6 = relation.getMemberPrimitivesList().get(5); 195 if (way6 instanceof Way) { 196 Way way = (Way) way6; 197 reverseWay(way); 198 returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 199 for (int i = 0; i < 7; i++) { 200 Assert.assertTrue(returned.get(i).onewayFollowsPrevious); 201 Assert.assertTrue(returned.get(i).onewayFollowsNext); 202 } 203 } 204 205 // Reverse everything 206 for (Way way : relation.getMemberPrimitives(Way.class)) { 207 reverseWay(way); 208 } 209 returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 210 for (int i = 0; i < 7; i++) { 211 Assert.assertTrue(returned.get(i).onewayFollowsPrevious); 212 Assert.assertTrue(returned.get(i).onewayFollowsNext); 213 } 214 } 215 216 /** 217 * Test directional {@link WayConnectionTypeCalculator#computeNextWayConnection} 218 */ 219 @Test 220 public void testDirectionsOnewayMix() { 221 Relation relation = getRelation("direction"); 222 223 // Remove the oneway in the wrong direction 224 OsmPrimitive osm = relation.getMemberPrimitivesList().get(5); 225 osm.remove("oneway"); 226 List<WayConnectionType> returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 227 for (WayConnectionType type : returned) { 228 Assert.assertTrue(type.onewayFollowsNext); 229 Assert.assertTrue(type.onewayFollowsPrevious); 230 } 231 232 // Check with a oneway=-1 tag without reversing the way 233 osm.put("oneway", "-1"); 234 returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 235 for (WayConnectionType type : returned) { 236 Assert.assertTrue(type.onewayFollowsNext); 237 Assert.assertTrue(type.onewayFollowsPrevious); 238 } 239 240 // Check with oneways that converge onto a two-way 241 // TODO figure out a way to find this situation? 242 osm.remove("oneway"); 243 OsmPrimitive way7 = relation.getMemberPrimitivesList().get(6); 244 way7.put("oneway", "-1"); 245 returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers()); 246 for (int i = 0; i < returned.size() - 1; i++) { 247 WayConnectionType type = returned.get(i); 248 Assert.assertTrue(type.onewayFollowsNext); 249 Assert.assertTrue(type.onewayFollowsPrevious); 250 } 251 Assert.assertTrue(returned.get(6).onewayFollowsNext); 252 Assert.assertFalse(returned.get(6).onewayFollowsPrevious); 253 } 133 254 }
Note:
See TracChangeset
for help on using the changeset viewer.