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

Last change on this file since 9214 was 9214, checked in by Don-vip, 6 years ago

use LatLon.ZERO instead of new LatLon(0, 0)

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.data.validation.tests
3
4import org.openstreetmap.josm.JOSMFixture
5import org.openstreetmap.josm.data.coor.LatLon
6import org.openstreetmap.josm.data.osm.DataSet
7import org.openstreetmap.josm.data.osm.Node
8import org.openstreetmap.josm.data.osm.Way
9
10class HighwaysTest extends GroovyTestCase {
11
12    @Override
13    void setUp() {
14        JOSMFixture.createUnitTestFixture().init();
15    }
16
17    public static Way createTestSetting(String highway, String highwayLink) {
18        def ds = new DataSet()
19
20        def n00 = new Node(LatLon.ZERO)
21        def n10 = new Node(new LatLon(1, 0))
22        def n20 = new Node(new LatLon(2, 0))
23        def n01 = new Node(new LatLon(0, 1))
24        def n11 = new Node(new LatLon(1, 1))
25        def n21 = new Node(new LatLon(2, 1))
26
27        ds.addPrimitive(n00)
28        ds.addPrimitive(n10)
29        ds.addPrimitive(n20)
30        ds.addPrimitive(n01)
31        ds.addPrimitive(n11)
32        ds.addPrimitive(n21)
33
34        def major = new Way()
35        major.addNode(n00)
36        major.addNode(n10)
37        major.addNode(n20)
38        major.put("highway", highway)
39        def link = new Way()
40        link.addNode(n10)
41        link.addNode(n11)
42        link.put("highway", highwayLink)
43        def unclassified = new Way()
44        unclassified.addNode(n01)
45        unclassified.addNode(n11)
46        unclassified.addNode(n21)
47        unclassified.put("highway", "unclassified")
48
49        ds.addPrimitive(major)
50        ds.addPrimitive(link)
51        ds.addPrimitive(unclassified)
52
53        return link
54    }
55
56    void testCombinations() {
57        assert Highways.isHighwayLinkOkay(createTestSetting("primary", "primary_link"))
58        assert Highways.isHighwayLinkOkay(createTestSetting("primary", "primary"))
59        assert !Highways.isHighwayLinkOkay(createTestSetting("primary", "secondary_link"))
60        assert !Highways.isHighwayLinkOkay(createTestSetting("secondary", "primary_link"))
61        assert !Highways.isHighwayLinkOkay(createTestSetting("secondary", "tertiary_link"))
62        assert Highways.isHighwayLinkOkay(createTestSetting("residential", "residential"))
63    }
64
65    void testSourceMaxSpeedUnitedKingdom() {
66        def link = createTestSetting("primary", "primary")
67        link.put("maxspeed", "60 mph")
68        link.put("source:maxspeed", "UK:nsl_single")
69        def test = new Highways()
70        test.visit(link)
71        assert test.errors.size() == 1
72        def error = test.errors.get(0)
73        assert error.isFixable()
74        assert error.getFix().executeCommand()
75        assert "GB:nsl_single".equals(link.get("source:maxspeed"))
76    }
77}
Note: See TracBrowser for help on using the repository browser.