Changeset 11403 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2016-12-15T08:13:49+01:00 (8 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/ConditionalKeysTest.java
r11390 r11403 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.validation.tests 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import org.openstreetmap.josm.JOSMFixture 4 import static org.junit.Assert.assertFalse; 5 import static org.junit.Assert.assertTrue; 6 7 import org.junit.Before; 8 import org.junit.Test; 9 import org.openstreetmap.josm.JOSMFixture; 5 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 6 11 7 class ConditionalKeysTest extends GroovyTestCase { 12 /** 13 * Unit test of {@link ConditionalKeys}. 14 */ 15 public class ConditionalKeysTest { 8 16 9 ConditionalKeys test = new ConditionalKeys()17 private final ConditionalKeys test = new ConditionalKeys(); 10 18 11 @Override 12 void setUp() { 19 /** 20 * Setup test 21 * @throws Exception if an error occurs 22 */ 23 @Before 24 public void setUp() throws Exception { 13 25 JOSMFixture.createUnitTestFixture().init(); 14 TaggingPresets.readFromPreferences() 15 test.initialize() 26 TaggingPresets.readFromPreferences(); 27 test.initialize(); 16 28 } 17 29 18 void testKeyValid() { 19 assert test.isKeyValid("maxspeed:conditional") 20 assert test.isKeyValid("motor_vehicle:conditional") 21 assert test.isKeyValid("bicycle:conditional") 22 assert test.isKeyValid("overtaking:hgv:conditional") 23 assert test.isKeyValid("maxspeed:hgv:backward:conditional") 24 assert test.isKeyValid("oneway:backward:conditional") 25 assert test.isKeyValid("fee:conditional") 26 assert !test.isKeyValid("maxspeed:hgv:conditional:backward") 30 /** 31 * Unit test of {@link ConditionalKeys#isKeyValid}. 32 */ 33 @Test 34 public void testKeyValid() { 35 assertTrue(test.isKeyValid("maxspeed:conditional")); 36 assertTrue(test.isKeyValid("motor_vehicle:conditional")); 37 assertTrue(test.isKeyValid("bicycle:conditional")); 38 assertTrue(test.isKeyValid("overtaking:hgv:conditional")); 39 assertTrue(test.isKeyValid("maxspeed:hgv:backward:conditional")); 40 assertTrue(test.isKeyValid("oneway:backward:conditional")); 41 assertTrue(test.isKeyValid("fee:conditional")); 42 assertFalse(test.isKeyValid("maxspeed:hgv:conditional:backward")); 27 43 } 28 44 29 void testValueValid() { 30 assert test.isValueValid("maxspeed:conditional", "120 @ (06:00-19:00)") 31 assert !test.isValueValid("maxspeed:conditional", " @ (06:00-19:00)") 32 assert !test.isValueValid("maxspeed:conditional", "120 (06:00-19:00)") 33 assert !test.isValueValid("maxspeed:conditional", "120 @ ()") 34 assert !test.isValueValid("maxspeed:conditional", "120 @ ") 35 assert !test.isValueValid("maxspeed:conditional", "120 @ (06:00/19:00)") 36 assert test.isValueValid("maxspeed:conditional", "120 @ (06:00-20:00); 100 @ (22:00-06:00)") 37 assert test.isValueValid("motor_vehicle:conditional", "delivery @ (Mo-Fr 06:00-11:00,17:00-19:00;Sa 03:30-19:00)") 38 assert test.isValueValid("motor_vehicle:conditional", "no @ (10:00-18:00 AND length>5)") 39 assert !test.isValueValid("motor_vehicle:conditional", "foo @ (10:00-18:00 AND length>5)") 40 assert !test.isValueValid("motor_vehicle:conditional", "no @ (10:00until18:00 AND length>5)") 41 assert test.isValueValid("maxspeed:hgv:conditional", "60 @ (weight>7.5)") 45 /** 46 * Unit test of {@link ConditionalKeys#isValueValid}. 47 */ 48 @Test 49 public void testValueValid() { 50 assertTrue(test.isValueValid("maxspeed:conditional", "120 @ (06:00-19:00)")); 51 assertFalse(test.isValueValid("maxspeed:conditional", " @ (06:00-19:00)")); 52 assertFalse(test.isValueValid("maxspeed:conditional", "120 (06:00-19:00)")); 53 assertFalse(test.isValueValid("maxspeed:conditional", "120 @ ()")); 54 assertFalse(test.isValueValid("maxspeed:conditional", "120 @ ")); 55 assertFalse(test.isValueValid("maxspeed:conditional", "120 @ (06:00/19:00)")); 56 assertTrue(test.isValueValid("maxspeed:conditional", "120 @ (06:00-20:00); 100 @ (22:00-06:00)")); 57 assertTrue(test.isValueValid("motor_vehicle:conditional", "delivery @ (Mo-Fr 06:00-11:00,17:00-19:00;Sa 03:30-19:00)")); 58 assertTrue(test.isValueValid("motor_vehicle:conditional", "no @ (10:00-18:00 AND length>5)")); 59 assertFalse(test.isValueValid("motor_vehicle:conditional", "foo @ (10:00-18:00 AND length>5)")); 60 assertFalse(test.isValueValid("motor_vehicle:conditional", "no @ (10:00until18:00 AND length>5)")); 61 assertTrue(test.isValueValid("maxspeed:hgv:conditional", "60 @ (weight>7.5)")); 42 62 } 43 63 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/HighwaysTest.java
r11390 r11403 1 // License: GPL. See LICENSE file for details.2 package org.openstreetmap.josm.data.validation.tests 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import org.openstreetmap.josm.JOSMFixture 5 import org.openstreetmap.josm.data.coor.LatLon 6 import org.openstreetmap.josm.data.osm.DataSet 7 import org.openstreetmap.josm.data.osm.Node 8 import org.openstreetmap.josm.data.osm.Way 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 9 7 10 class HighwaysTest extends GroovyTestCase { 8 import org.junit.Before; 9 import org.junit.Test; 10 import org.openstreetmap.josm.JOSMFixture; 11 import org.openstreetmap.josm.data.coor.LatLon; 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm.Node; 14 import org.openstreetmap.josm.data.osm.Way; 15 import org.openstreetmap.josm.data.validation.TestError; 11 16 12 @Override 13 void setUp() { 17 /** 18 * Unit test of {@link HighwaysTest}. 19 */ 20 public class HighwaysTest { 21 22 /** 23 * Setup test. 24 */ 25 @Before 26 public void setUp() { 14 27 JOSMFixture.createUnitTestFixture().init(); 15 28 } 16 29 17 p ublicstatic Way createTestSetting(String highway, String highwayLink) {18 def ds = new DataSet()30 private static Way createTestSetting(String highway, String highwayLink) { 31 DataSet ds = new DataSet(); 19 32 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))33 Node n00 = new Node(LatLon.ZERO); 34 Node n10 = new Node(new LatLon(1, 0)); 35 Node n20 = new Node(new LatLon(2, 0)); 36 Node n01 = new Node(new LatLon(0, 1)); 37 Node n11 = new Node(new LatLon(1, 1)); 38 Node n21 = new Node(new LatLon(2, 1)); 26 39 27 ds.addPrimitive(n00) 28 ds.addPrimitive(n10) 29 ds.addPrimitive(n20) 30 ds.addPrimitive(n01) 31 ds.addPrimitive(n11) 32 ds.addPrimitive(n21) 40 ds.addPrimitive(n00); 41 ds.addPrimitive(n10); 42 ds.addPrimitive(n20); 43 ds.addPrimitive(n01); 44 ds.addPrimitive(n11); 45 ds.addPrimitive(n21); 33 46 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") 47 Way major = new Way(); 48 major.addNode(n00); 49 major.addNode(n10); 50 major.addNode(n20); 51 major.put("highway", highway); 52 Way link = new Way(); 53 link.addNode(n10); 54 link.addNode(n11); 55 link.put("highway", highwayLink); 56 Way unclassified = new Way(); 57 unclassified.addNode(n01); 58 unclassified.addNode(n11); 59 unclassified.addNode(n21); 60 unclassified.put("highway", "unclassified"); 48 61 49 ds.addPrimitive(major) 50 ds.addPrimitive(link) 51 ds.addPrimitive(unclassified) 62 ds.addPrimitive(major); 63 ds.addPrimitive(link); 64 ds.addPrimitive(unclassified); 52 65 53 return link 66 return link; 54 67 } 55 68 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")) 69 /** 70 * Unit test of {@link Highways#isHighwayLinkOkay}. 71 */ 72 @Test 73 public void testCombinations() { 74 assertTrue(Highways.isHighwayLinkOkay(createTestSetting("primary", "primary_link"))); 75 assertTrue(Highways.isHighwayLinkOkay(createTestSetting("primary", "primary"))); 76 assertFalse(Highways.isHighwayLinkOkay(createTestSetting("primary", "secondary_link"))); 77 assertFalse(Highways.isHighwayLinkOkay(createTestSetting("secondary", "primary_link"))); 78 assertFalse(Highways.isHighwayLinkOkay(createTestSetting("secondary", "tertiary_link"))); 79 assertTrue(Highways.isHighwayLinkOkay(createTestSetting("residential", "residential"))); 63 80 } 64 81 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")) 82 /** 83 * Test source:maxspeed in United Kingdom. 84 */ 85 @Test 86 public void testSourceMaxSpeedUnitedKingdom() { 87 Way link = createTestSetting("primary", "primary"); 88 link.put("maxspeed", "60 mph"); 89 link.put("source:maxspeed", "UK:nsl_single"); 90 Highways test = new Highways(); 91 test.visit(link); 92 assertEquals(1, test.getErrors().size()); 93 TestError error = test.getErrors().get(0); 94 assertTrue(error.isFixable()); 95 assertTrue(error.getFix().executeCommand()); 96 assertEquals("GB:nsl_single", link.get("source:maxspeed")); 76 97 } 77 98 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/LanesTest.java
r11390 r11403 1 package org.openstreetmap.josm.data.validation.tests 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.validation.tests; 2 3 3 import org.openstreetmap.josm.JOSMFixture4 import org.openstreetmap.josm.data.osm.OsmUtils4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue; 5 6 6 class LanesTest extends GroovyTestCase { 7 import org.junit.Before; 8 import org.junit.Test; 9 import org.openstreetmap.josm.JOSMFixture; 10 import org.openstreetmap.josm.data.osm.OsmUtils; 7 11 8 Lanes lanes = new Lanes() 12 /** 13 * Unit tests of {@link Lanes}. 14 */ 15 public class LanesTest { 9 16 10 @Override 11 void setUp() { 12 JOSMFixture.createUnitTestFixture().init() 13 lanes.initialize() 14 lanes.startTest(null) 17 private final Lanes lanes = new Lanes(); 18 19 /** 20 * Setup test. 21 * @throws Exception if an error occurs 22 */ 23 @Before 24 public void setUp() throws Exception { 25 JOSMFixture.createUnitTestFixture().init(); 26 lanes.initialize(); 27 lanes.startTest(null); 15 28 } 16 29 17 void testLanesCount() { 18 assert lanes.getLanesCount("") == 0 19 assert lanes.getLanesCount("left") == 1 20 assert lanes.getLanesCount("left|right") == 2 21 assert lanes.getLanesCount("yes|no|yes") == 3 22 assert lanes.getLanesCount("yes||") == 3 30 /** 31 * Unit test of {@link Lanes#getLanesCount}. 32 */ 33 @Test 34 public void testLanesCount() { 35 assertEquals(0, Lanes.getLanesCount("")); 36 assertEquals(1, Lanes.getLanesCount("left")); 37 assertEquals(2, Lanes.getLanesCount("left|right")); 38 assertEquals(3, Lanes.getLanesCount("yes|no|yes")); 39 assertEquals(3, Lanes.getLanesCount("yes||")); 23 40 } 24 41 25 void test1() { 26 lanes.check(OsmUtils.createPrimitive("way turn:lanes=left|right change:lanes=only_left|not_right|yes")) 27 assert lanes.errors.get(0).getMessage() == "Number of lane dependent values inconsistent" 42 @Test 43 public void test1() { 44 lanes.check(OsmUtils.createPrimitive("way turn:lanes=left|right change:lanes=only_left|not_right|yes")); 45 assertEquals("Number of lane dependent values inconsistent", lanes.getErrors().get(0).getMessage()); 28 46 } 29 47 30 void test2() { 31 lanes.check(OsmUtils.createPrimitive("way width:lanes:forward=1|2|3 psv:lanes:forward=no|designated")) 32 assert lanes.errors.get(0).getMessage() == "Number of lane dependent values inconsistent in forward direction" 48 @Test 49 public void test2() { 50 lanes.check(OsmUtils.createPrimitive("way width:lanes:forward=1|2|3 psv:lanes:forward=no|designated")); 51 assertEquals("Number of lane dependent values inconsistent in forward direction", lanes.getErrors().get(0).getMessage()); 33 52 } 34 53 35 void test3() { 36 lanes.check(OsmUtils.createPrimitive("way change:lanes:forward=yes|no turn:lanes:backward=left|right|left")) 37 assert lanes.errors.isEmpty() 54 @Test 55 public void test3() { 56 lanes.check(OsmUtils.createPrimitive("way change:lanes:forward=yes|no turn:lanes:backward=left|right|left")); 57 assertTrue(lanes.getErrors().isEmpty()); 38 58 } 39 59 40 void test4() { 41 lanes.check(OsmUtils.createPrimitive("way turn:lanes:forward=left|right change:lanes:forward=yes|no|yes width:backward=1|2|3")) 42 assert lanes.errors.get(0).getMessage() == "Number of lane dependent values inconsistent in forward direction" 60 @Test 61 public void test4() { 62 lanes.check(OsmUtils.createPrimitive("way turn:lanes:forward=left|right change:lanes:forward=yes|no|yes width:backward=1|2|3")); 63 assertEquals("Number of lane dependent values inconsistent in forward direction", lanes.getErrors().get(0).getMessage()); 43 64 } 44 65 45 void test5() { 46 lanes.check(OsmUtils.createPrimitive("way lanes:forward=5 turn:lanes:forward=left|right")) 47 assert lanes.errors.get(0).getMessage() == "Number of lanes:forward greater than *:lanes:forward" 66 @Test 67 public void test5() { 68 lanes.check(OsmUtils.createPrimitive("way lanes:forward=5 turn:lanes:forward=left|right")); 69 assertEquals("Number of lanes:forward greater than *:lanes:forward", lanes.getErrors().get(0).getMessage()); 48 70 } 49 71 50 void test6() { 51 lanes.check(OsmUtils.createPrimitive("way lanes:forward=foo|bar turn:lanes:forward=foo+bar")) 52 assert lanes.errors.isEmpty() 72 @Test 73 public void test6() { 74 lanes.check(OsmUtils.createPrimitive("way lanes:forward=foo|bar turn:lanes:forward=foo+bar")); 75 assertTrue(lanes.getErrors().isEmpty()); 53 76 } 54 77 55 void test7() { 56 lanes.check(OsmUtils.createPrimitive("way lanes=3 lanes:forward=3 lanes:backward=7")) 57 assert lanes.errors.get(0).getMessage() == "Number of lanes:forward+lanes:backward greater than lanes" 78 @Test 79 public void test7() { 80 lanes.check(OsmUtils.createPrimitive("way lanes=3 lanes:forward=3 lanes:backward=7")); 81 assertEquals("Number of lanes:forward+lanes:backward greater than lanes", lanes.getErrors().get(0).getMessage()); 58 82 } 59 83 60 void test8() { 61 lanes.check(OsmUtils.createPrimitive("way destination:country:lanes=X|Y;Z|none destination:ref:lanes=xyz|| destination:sign:lanes=none|airport|none")) 62 assert lanes.errors.isEmpty() 84 @Test 85 public void test8() { 86 lanes.check(OsmUtils.createPrimitive( 87 "way destination:country:lanes=X|Y;Z|none destination:ref:lanes=xyz|| destination:sign:lanes=none|airport|none")); 88 assertTrue(lanes.getErrors().isEmpty()); 63 89 } 64 90 65 void test9() { 66 lanes.check(OsmUtils.createPrimitive("way highway=secondary lanes=2 source:lanes=survey")) 67 assert lanes.errors.isEmpty() 91 @Test 92 public void test9() { 93 lanes.check(OsmUtils.createPrimitive("way highway=secondary lanes=2 source:lanes=survey")); 94 assertTrue(lanes.getErrors().isEmpty()); 68 95 } 69 96 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.java
r11390 r11403 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.validation.tests 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import static org.openstreetmap.josm.data.osm.OsmUtils.createPrimitive 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertTrue; 6 import static org.openstreetmap.josm.data.osm.OsmUtils.createPrimitive; 5 7 6 import org.openstreetmap.josm.JOSMFixture 7 import org.openstreetmap.josm.data.osm.Relation 8 import org.openstreetmap.josm.data.osm.RelationMember 9 import org.openstreetmap.josm.data.osm.Way 10 import org.openstreetmap.josm.data.validation.TestError 8 import java.util.List; 9 10 import org.junit.Before; 11 import org.junit.Test; 12 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.data.osm.Relation; 14 import org.openstreetmap.josm.data.osm.RelationMember; 15 import org.openstreetmap.josm.data.osm.Way; 16 import org.openstreetmap.josm.data.validation.TestError; 11 17 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 12 18 13 class RelationCheckerTest extends GroovyTestCase{19 public class RelationCheckerTest { 14 20 15 @Override 16 void setUp() { 21 /** 22 * Setup test. 23 */ 24 @Before 25 public void setUp() { 17 26 JOSMFixture.createUnitTestFixture().init(); 18 getRelationChecker() 27 getRelationChecker(); 19 28 } 20 29 21 static defRelationChecker getRelationChecker() {22 def checker = new RelationChecker()23 TaggingPresets.readFromPreferences() 24 checker.initialize() 25 return checker 30 private static RelationChecker getRelationChecker() { 31 RelationChecker checker = new RelationChecker(); 32 TaggingPresets.readFromPreferences(); 33 checker.initialize(); 34 return checker; 26 35 } 27 36 28 static defList<TestError> testRelation(Relation r) {29 def checker = getRelationChecker()30 checker.visit(r) 31 return checker.getErrors() 37 private static List<TestError> testRelation(Relation r) { 38 RelationChecker checker = getRelationChecker(); 39 checker.visit(r); 40 return checker.getErrors(); 32 41 } 33 42 34 static defRelation createRelation(String tags) {35 return (Relation) createPrimitive("relation "+ tags) 43 private static Relation createRelation(String tags) { 44 return (Relation) createPrimitive("relation "+ tags); 36 45 } 37 46 38 void testUnknownType() { 39 def errors = testRelation(createRelation("type=foobar")) 40 assert errors.size() >= 1 41 assert errors.get(0).getMessage() == "Relation type is unknown" 47 @Test 48 public void testUnknownType() { 49 List<TestError> errors = testRelation(createRelation("type=foobar")); 50 assertTrue(errors.size() >= 1); 51 assertEquals("Relation type is unknown", errors.get(0).getMessage()); 42 52 } 43 53 44 void testEmpty() { 45 def errors = testRelation(createRelation("type=multipolygon")) 46 assert errors.size() == 1 47 assert errors.get(0).getMessage() == "Relation is empty" 54 @Test 55 public void testEmpty() { 56 List<TestError> errors = testRelation(createRelation("type=multipolygon")); 57 assertEquals(1, errors.size()); 58 assertEquals("Relation is empty", errors.get(0).getMessage()); 48 59 } 49 60 50 void testNormal() { 51 def r = createRelation("type=multipolygon") 52 r.addMember(new RelationMember("outer", new Way())) 53 r.addMember(new RelationMember("inner", new Way())) 54 assert testRelation(r).isEmpty() 61 @Test 62 public void testNormal() { 63 Relation r = createRelation("type=multipolygon"); 64 r.addMember(new RelationMember("outer", new Way())); 65 r.addMember(new RelationMember("inner", new Way())); 66 assertTrue(testRelation(r).isEmpty()); 55 67 } 56 68 57 void testOuter2() { 58 def r = createRelation("type=multipolygon") 59 r.addMember(new RelationMember("outer", new Way())) 60 r.addMember(new RelationMember("outer2", new Way())) 69 @Test 70 public void testOuter2() { 71 Relation r = createRelation("type=multipolygon"); 72 r.addMember(new RelationMember("outer", new Way())); 73 r.addMember(new RelationMember("outer2", new Way())); 61 74 62 def errors = testRelation(r)63 assert errors.size() == 164 assert errors.get(0).getDescription() == "Role outer2 unknown in templates outer/inner"75 List<TestError> errors = testRelation(r); 76 assertEquals(1, errors.size()); 77 assertEquals("Role outer2 unknown in templates outer/inner", errors.get(0).getDescription()); 65 78 } 66 79 67 void testRestrictionViaMissing() { 68 def r = createRelation("type=restriction") 69 r.addMember(new RelationMember("from", new Way())) 70 r.addMember(new RelationMember("to", new Way())) 80 @Test 81 public void testRestrictionViaMissing() { 82 Relation r = createRelation("type=restriction"); 83 r.addMember(new RelationMember("from", new Way())); 84 r.addMember(new RelationMember("to", new Way())); 71 85 72 def errors = testRelation(r)73 assert errors.size() == 174 assert errors.get(0).getDescription() == "Role via missing"86 List<TestError> errors = testRelation(r); 87 assertEquals(1, errors.size()); 88 assertEquals("Role via missing", errors.get(0).getDescription()); 75 89 } 76 90 77 void testRestrictionViaRelation() { 78 def r = createRelation("type=restriction") 79 r.addMember(new RelationMember("from", new Way())) 80 r.addMember(new RelationMember("to", new Way())) 81 r.addMember(new RelationMember("via", new Relation())) 91 @Test 92 public void testRestrictionViaRelation() { 93 Relation r = createRelation("type=restriction"); 94 r.addMember(new RelationMember("from", new Way())); 95 r.addMember(new RelationMember("to", new Way())); 96 r.addMember(new RelationMember("via", new Relation())); 82 97 83 def errors = testRelation(r) 84 assert errors.size() == 1 85 assert errors.get(0).getDescription() == "Role member type relation does not match accepted list of node/way in template Turn Restriction" 98 List<TestError> errors = testRelation(r); 99 assertEquals(1, errors.size()); 100 assertEquals("Role member type relation does not match accepted list of node/way in template Turn Restriction", 101 errors.get(0).getDescription()); 86 102 } 87 103 88 void testRestrictionTwoFrom() { 89 def r = createRelation("type=restriction") 90 r.addMember(new RelationMember("from", new Way())) 91 r.addMember(new RelationMember("from", new Way())) 92 r.addMember(new RelationMember("to", new Way())) 93 r.addMember(new RelationMember("via", new Way())) 104 @Test 105 public void testRestrictionTwoFrom() { 106 Relation r = createRelation("type=restriction"); 107 r.addMember(new RelationMember("from", new Way())); 108 r.addMember(new RelationMember("from", new Way())); 109 r.addMember(new RelationMember("to", new Way())); 110 r.addMember(new RelationMember("via", new Way())); 94 111 95 def errors = testRelation(r)96 assert errors.size() == 197 assert errors.get(0).getDescription() == "Number of from roles too high (2)"112 List<TestError> errors = testRelation(r); 113 assertEquals(1, errors.size()); 114 assertEquals("Number of from roles too high (2)", errors.get(0).getDescription()); 98 115 } 99 116 100 void testRestrictionEmpty() { 101 def r = createRelation("type=restriction") 102 r.addMember(new RelationMember("from", new Way())) 103 r.addMember(new RelationMember("to", new Way())) 104 r.addMember(new RelationMember("via", new Way())) 105 r.addMember(new RelationMember("", new Way())) 117 @Test 118 public void testRestrictionEmpty() { 119 Relation r = createRelation("type=restriction"); 120 r.addMember(new RelationMember("from", new Way())); 121 r.addMember(new RelationMember("to", new Way())); 122 r.addMember(new RelationMember("via", new Way())); 123 r.addMember(new RelationMember("", new Way())); 106 124 107 def errors = testRelation(r)108 assert errors.size() == 1109 assert errors.get(0).getDescription().startsWith("Empty role type found when expecting one of")125 List<TestError> errors = testRelation(r); 126 assertEquals(1, errors.size()); 127 assertTrue(errors.get(0).getDescription().startsWith("Empty role type found when expecting one of")); 110 128 } 111 129 112 void testPowerMemberExpression() { 113 def r = createRelation("type=route route=power") 114 r.addMember(new RelationMember("", new Way())) 130 @Test 131 public void testPowerMemberExpression() { 132 Relation r = createRelation("type=route route=power"); 133 r.addMember(new RelationMember("", new Way())); 115 134 116 def errors = testRelation(r)117 assert errors.size() == 1118 assert errors.get(0).getDescription() == "Role member does not match expression power in template Power Route"135 List<TestError> errors = testRelation(r); 136 assertEquals(1, errors.size()); 137 assertEquals("Role member does not match expression power in template Power Route", errors.get(0).getDescription()); 119 138 } 120 139 121 void testRouteMemberExpression() { 122 def r = createRelation("type=route route=tram public_transport:version=2") 123 r.addMember(new RelationMember("", createPrimitive("way railway=tram"))) 124 r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position tram=yes"))) 125 r.addMember(new RelationMember("platform", createPrimitive("node public_transport=platform tram=yes"))) 126 assert testRelation(r).size() == 0 140 @Test 141 public void testRouteMemberExpression() { 142 Relation r = createRelation("type=route route=tram public_transport:version=2"); 143 r.addMember(new RelationMember("", createPrimitive("way railway=tram"))); 144 r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position tram=yes"))); 145 r.addMember(new RelationMember("platform", createPrimitive("node public_transport=platform tram=yes"))); 146 assertTrue(testRelation(r).isEmpty()); 127 147 128 r.addMember(new RelationMember("", createPrimitive("way no-rail-way=yes"))) 129 assert testRelation(r).size() == 1 130 assert testRelation(r).get(0).getDescription() == "Role member does not match expression railway in template Public Transport Route (Rail)" 148 r.addMember(new RelationMember("", createPrimitive("way no-rail-way=yes"))); 149 assertEquals(1, testRelation(r).size()); 150 assertEquals("Role member does not match expression railway in template Public Transport Route (Rail)", 151 testRelation(r).get(0).getDescription()); 131 152 132 r.removeMember(3) 133 r.addMember(new RelationMember("stop", createPrimitive("way no-rail-way=yes"))) 134 assert testRelation(r).size() == 1 135 assert testRelation(r).get(0).getDescription() == "Role member type way does not match accepted list of node in template Public Transport Route (Rail)" 153 r.removeMember(3); 154 r.addMember(new RelationMember("stop", createPrimitive("way no-rail-way=yes"))); 155 assertEquals(1, testRelation(r).size()); 156 assertEquals("Role member type way does not match accepted list of node in template Public Transport Route (Rail)", 157 testRelation(r).get(0).getDescription()); 136 158 137 r.removeMember(3) 138 r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position bus=yes"))) 139 assert testRelation(r).size() == 1 140 assert testRelation(r).get(0).getDescription() == "Role member does not match expression public_transport=stop_position && (train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes) in template Public Transport Route (Rail)" 159 r.removeMember(3); 160 r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position bus=yes"))); 161 assertEquals(1, testRelation(r).size()); 162 assertEquals("Role member does not match expression public_transport=stop_position && "+ 163 "(train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes) in template Public Transport Route (Rail)", 164 testRelation(r).get(0).getDescription()); 141 165 } 142 166 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/SimilarNamedWaysTest.java
r11390 r11403 1 // License: GPL. See LICENSE file for details.2 package org.openstreetmap.josm.data.validation.tests 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.validation.tests; 3 3 4 import static org.junit.Assert.assertEquals 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 5 7 6 import org.openstreetmap.josm.JOSMFixture 7 import org.openstreetmap.josm.data.coor.LatLon 8 import org.openstreetmap.josm.data.osm.DataSet 9 import org.openstreetmap.josm.data.osm.Node 10 import org.openstreetmap.josm.data.osm.Way 11 import org.openstreetmap.josm.data.validation.TestError 8 import java.util.List; 12 9 13 class SimilarNamedWaysTest extends GroovyTestCase { 10 import org.junit.Before; 11 import org.junit.Test; 12 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.data.validation.TestError; 14 18 15 SimilarNamedWays test = new SimilarNamedWays() 19 /** 20 * Unit test of {@link SimilarNamedWays} 21 */ 22 public class SimilarNamedWaysTest { 16 23 17 @Override 18 void setUp() { 24 private final SimilarNamedWays test = new SimilarNamedWays(); 25 26 /** 27 * Setup test 28 */ 29 @Before 30 public void setUp() { 19 31 JOSMFixture.createUnitTestFixture().init(); 20 32 } 21 33 22 p ublicstatic List<TestError> testWays(String namea, String nameb) {23 def ds = new DataSet()34 private static List<TestError> testWays(String namea, String nameb) { 35 DataSet ds = new DataSet(); 24 36 25 def n00 = new Node(LatLon.ZERO)26 def n10 = new Node(new LatLon(1, 0))27 def n20 = new Node(new LatLon(2, 0))28 def n30 = new Node(new LatLon(3, 0))29 def n40 = new Node(new LatLon(4, 0))37 Node n00 = new Node(LatLon.ZERO); 38 Node n10 = new Node(new LatLon(1, 0)); 39 Node n20 = new Node(new LatLon(2, 0)); 40 Node n30 = new Node(new LatLon(3, 0)); 41 Node n40 = new Node(new LatLon(4, 0)); 30 42 31 ds.addPrimitive(n00) 32 ds.addPrimitive(n10) 33 ds.addPrimitive(n20) 34 ds.addPrimitive(n30) 35 ds.addPrimitive(n40) 43 ds.addPrimitive(n00); 44 ds.addPrimitive(n10); 45 ds.addPrimitive(n20); 46 ds.addPrimitive(n30); 47 ds.addPrimitive(n40); 36 48 37 def waya = new Way()38 waya.addNode(n00) 39 waya.addNode(n10) 40 waya.addNode(n20) 41 waya.put("name", namea) 42 def wayb = new Way()43 wayb.addNode(n20) 44 wayb.addNode(n30) 45 wayb.addNode(n40) 46 wayb.put("name", nameb) 49 Way waya = new Way(); 50 waya.addNode(n00); 51 waya.addNode(n10); 52 waya.addNode(n20); 53 waya.put("name", namea); 54 Way wayb = new Way(); 55 wayb.addNode(n20); 56 wayb.addNode(n30); 57 wayb.addNode(n40); 58 wayb.put("name", nameb); 47 59 48 ds.addPrimitive(waya) 49 ds.addPrimitive(wayb) 60 ds.addPrimitive(waya); 61 ds.addPrimitive(wayb); 50 62 51 assert waya.isUsable()52 assert wayb.isUsable()63 assertTrue(waya.isUsable()); 64 assertTrue(wayb.isUsable()); 53 65 54 def t = new SimilarNamedWays()55 t.startTest(null) 56 t.visit(waya) 57 t.visit(wayb) 58 return t. errors66 SimilarNamedWays t = new SimilarNamedWays(); 67 t.startTest(null); 68 t.visit(waya); 69 t.visit(wayb); 70 return t.getErrors(); 59 71 } 60 72 61 void testCombinations() { 62 assert testWays("Church Street", "Water Street").isEmpty() 63 assert !testWays("Main Street", "Maim Street").isEmpty() 64 assert !testWays("First Street", "Frist Street").isEmpty() 73 @Test 74 public void testCombinations() { 75 assertTrue(testWays("Church Street", "Water Street").isEmpty()); 76 assertFalse(testWays("Main Street", "Maim Street").isEmpty()); 77 assertFalse(testWays("First Street", "Frist Street").isEmpty()); 65 78 66 assert testWays("1st Street", "2nd Street").isEmpty()67 assert testWays("First Avenue", "Second Avenue").isEmpty()68 assert testWays("West Main Street", "East Main Street").isEmpty()69 assert testWays("A Street", "B Street").isEmpty()79 assertTrue(testWays("1st Street", "2nd Street").isEmpty()); 80 assertTrue(testWays("First Avenue", "Second Avenue").isEmpty()); 81 assertTrue(testWays("West Main Street", "East Main Street").isEmpty()); 82 assertTrue(testWays("A Street", "B Street").isEmpty()); 70 83 } 71 84 72 void checkSimilarity(String message, String name1, String name2, boolean expected) {85 private void checkSimilarity(String message, String name1, String name2, boolean expected) { 73 86 boolean actual = test.similaryName(name1, name2); 74 87 assertEquals(message, expected, actual); 75 88 } 76 89 77 void testSimilarNames() { 90 @Test 91 public void testSimilarNames() { 78 92 checkSimilarity("same string", "Testname", "Testname", false); 79 93 checkSimilarity("different case", "Testname", "TestName", true);
Note:
See TracChangeset
for help on using the changeset viewer.