source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/tests/HighwaysTest.groovy@ 6573

Last change on this file since 6573 was 6573, checked in by simon04, 10 years ago

fix #9043 - Validator: Verify links on highways

File size: 2.4 KB
RevLine 
[6573]1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.data.validation.tests
3
4import org.openstreetmap.josm.Main
5import org.openstreetmap.josm.data.coor.LatLon
6import org.openstreetmap.josm.data.osm.DataSet
7import org.openstreetmap.josm.data.osm.Way
8import org.openstreetmap.josm.data.projection.Projections
9
10class HighwaysTest extends GroovyTestCase {
11
12 @Override
13 void setUp() {
14 Main.initApplicationPreferences()
15 Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
16 }
17
18 public static Way createTestSetting(String highway, String highwayLink) {
19 def ds = new DataSet()
20
21 def n00 = new org.openstreetmap.josm.data.osm.Node(new LatLon(0, 0))
22 def n10 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1, 0))
23 def n20 = new org.openstreetmap.josm.data.osm.Node(new LatLon(2, 0))
24 def n01 = new org.openstreetmap.josm.data.osm.Node(new LatLon(0, 1))
25 def n11 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1, 1))
26 def n21 = new org.openstreetmap.josm.data.osm.Node(new LatLon(2, 1))
27
28 ds.addPrimitive(n00)
29 ds.addPrimitive(n10)
30 ds.addPrimitive(n20)
31 ds.addPrimitive(n01)
32 ds.addPrimitive(n11)
33 ds.addPrimitive(n21)
34
35 def major = new Way()
36 major.addNode(n00)
37 major.addNode(n10)
38 major.addNode(n20)
39 major.put("highway", highway)
40 def link = new Way()
41 link.addNode(n10)
42 link.addNode(n11)
43 link.put("highway", highwayLink)
44 def unclassified = new Way()
45 unclassified.addNode(n01)
46 unclassified.addNode(n11)
47 unclassified.addNode(n21)
48 unclassified.put("highway", "unclassified")
49
50 ds.addPrimitive(major)
51 ds.addPrimitive(link)
52 ds.addPrimitive(unclassified)
53
54 return link
55 }
56
57 void testCombinations() {
58 assert Highways.isHighwayLinkOkay(createTestSetting("primary", "primary_link"))
59 assert Highways.isHighwayLinkOkay(createTestSetting("primary", "primary"))
60 assert !Highways.isHighwayLinkOkay(createTestSetting("primary", "secondary_link"))
61 assert !Highways.isHighwayLinkOkay(createTestSetting("secondary", "primary_link"))
62 assert !Highways.isHighwayLinkOkay(createTestSetting("secondary", "tertiary_link"))
63 assert Highways.isHighwayLinkOkay(createTestSetting("residential", "residential"))
64 }
65}
Note: See TracBrowser for help on using the repository browser.