Changeset 23189 in osm for applications/editors/josm/plugins/graphview/test
- Timestamp:
- 2010-09-15T18:53:09+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/FullGraphCreationTest.java
r19216 r23189 32 32 public class FullGraphCreationTest { 33 33 34 35 36 37 38 34 private static final AccessParameters ACCESS_PARAMS; 35 static { 36 Map<VehiclePropertyType<?>, String> vehiclePropertyValues = 37 new HashMap<VehiclePropertyType<?>, String>(); 38 vehiclePropertyValues.put(VehiclePropertyTypes.WIDTH, "3.0"); 39 39 40 41 42 43 44 45 46 47 48 40 try { 41 ACCESS_PARAMS = new PreferenceAccessParameters( 42 "test_vehicle", 43 Arrays.asList(AccessType.UNDEFINED), 44 vehiclePropertyValues); 45 } catch (PropertyValueSyntaxException e) { 46 throw new Error(e); 47 } 48 } 49 49 50 51 52 53 54 55 56 57 58 59 60 50 private static final AccessRuleset TEST_RULESET = new AccessRuleset() { 51 public java.util.List<String> getAccessHierarchyAncestors(String transportMode) { 52 return Arrays.asList(transportMode); 53 } 54 public java.util.Collection<Tag> getBaseTags() { 55 return Arrays.asList(new Tag("highway", "test")); 56 } 57 public java.util.List<Implication> getImplications() { 58 return new LinkedList<Implication>(); 59 } 60 }; 61 61 62 63 62 @Test 63 public void testTJunction() { 64 64 65 65 TestDataSource ds = new TestDataSource(); 66 66 67 68 69 70 67 TestNode nodeN = new TestNode(2, 1); 68 TestNode nodeW = new TestNode(1, 0); 69 TestNode nodeS = new TestNode(0, 1); 70 TestNode nodeC = new TestNode(1, 1); 71 71 72 72 ds.nodes.addAll(Arrays.asList(nodeN, nodeW, nodeS, nodeC)); 73 73 74 75 76 77 78 79 80 81 82 74 TestWay wayNC = new TestWay(); 75 wayNC.tags.put("highway", "test"); 76 wayNC.nodes.addAll(Arrays.asList(nodeN, nodeC)); 77 TestWay wayCS = new TestWay(); 78 wayCS.tags.put("highway", "test"); 79 wayCS.nodes.addAll(Arrays.asList(nodeC, nodeS)); 80 TestWay wayCW = new TestWay(); 81 wayCW.tags.put("highway", "test"); 82 wayCW.nodes.addAll(Arrays.asList(nodeC, nodeW)); 83 83 84 85 86 84 ds.ways.add(wayNC); 85 ds.ways.add(wayCS); 86 ds.ways.add(wayCW); 87 87 88 89 90 88 /* variant 1: no restrictions */ 89 { 90 TransitionStructure ts1 = createTestTransitionStructure(ds); 91 91 92 93 94 92 assertSame(4, size(ts1.getNodes())); 93 assertSame(6, size(ts1.getSegments())); 94 assertSame(0, size(ts1.getRestrictions())); 95 95 96 96 WayGraph graph1 = new TSBasedWayGraph(ts1); 97 97 98 99 100 101 102 103 104 98 assertSame(12, graph1.getNodes().size()); 99 assertSame(24, graph1.getEdges().size()); 100 } 101 /* variant 2: no left turn from S to W */ 102 { 103 ds.relations.add(createTurnRestrictionRelation(wayCS, nodeC, wayCW, "no_left_turn")); 104 TransitionStructure ts2 = createTestTransitionStructure(ds); 105 105 106 107 108 106 assertSame(4, size(ts2.getNodes())); 107 assertSame(6, size(ts2.getSegments())); 108 assertSame(1, size(ts2.getRestrictions())); 109 109 110 110 WayGraph graph2 = new TSBasedWayGraph(ts2); 111 111 112 113 114 112 assertSame(12, graph2.getNodes().size()); 113 assertSame(23, graph2.getEdges().size()); 114 } 115 115 116 116 } 117 117 118 119 118 @Test 119 public void testBarrier() { 120 120 121 121 TestDataSource ds = new TestDataSource(); 122 122 123 124 125 126 123 TestNode node1 = new TestNode(0, 1); 124 TestNode nodeB = new TestNode(0, 2); 125 nodeB.tags.put("width", "1"); 126 TestNode node2 = new TestNode(0, 3); 127 127 128 128 ds.nodes.addAll(Arrays.asList(node1, nodeB, node2)); 129 129 130 131 132 133 134 130 TestWay way = new TestWay(); 131 way.tags.put("highway", "test"); 132 way.tags.put("oneway", "yes"); 133 way.nodes.addAll(Arrays.asList(node1, nodeB, node2)); 134 ds.ways.add(way); 135 135 136 136 /* variant 1: no restrictions */ 137 137 138 138 TransitionStructure ts = createTestTransitionStructure(ds); 139 139 140 141 142 140 assertSame(3, size(ts.getNodes())); 141 assertSame(2, size(ts.getSegments())); 142 assertSame(1, size(ts.getRestrictions())); 143 143 144 144 WayGraph graph = new TSBasedWayGraph(ts); 145 145 146 147 146 assertSame(4, graph.getNodes().size()); 147 assertSame(2, graph.getEdges().size()); 148 148 149 149 } 150 150 151 152 153 154 155 156 157 158 159 160 151 private TestRelation createTurnRestrictionRelation( 152 TestWay from, TestNode via, TestWay to, String restriction) { 153 TestRelation resultRelation = new TestRelation(); 154 resultRelation.tags.put("type", "restriction"); 155 resultRelation.tags.put("restriction", restriction); 156 resultRelation.members.add(new TestRelationMember("from", from)); 157 resultRelation.members.add(new TestRelationMember("via", via)); 158 resultRelation.members.add(new TestRelationMember("to", to)); 159 return resultRelation; 160 } 161 161 162 162 private TransitionStructure createTestTransitionStructure(TestDataSource dataSource) { 163 163 164 165 164 LinkedList<RoadPropertyType<?>> properties = new LinkedList<RoadPropertyType<?>>(); 165 properties.add(new RoadWidth()); 166 166 167 168 169 167 return new GenericTransitionStructure<TestNode, TestWay, TestRelation, TestRelationMember>( 168 ACCESS_PARAMS, TEST_RULESET, dataSource, properties); 169 } 170 170 171 172 173 174 175 176 177 178 179 171 private static int size(Iterable<?> iterable) { 172 Iterator<?> iterator = iterable.iterator(); 173 int size = 0; 174 while (iterator.hasNext()) { 175 iterator.next(); 176 size ++; 177 } 178 return size; 179 } 180 180 181 181 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/TestDataSource.java
r19216 r23189 14 14 public class TestDataSource implements DataSource<TestDataSource.TestNode, TestDataSource.TestWay, TestDataSource.TestRelation, TestDataSource.TestRelationMember> { 15 15 16 17 18 16 public static class TestPrimitive { 17 public final Map<String, String> tags = new HashMap<String, String>(); 18 }; 19 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 20 public static class TestNode extends TestPrimitive { 21 public final double lat; 22 public final double lon; 23 public TestNode() { 24 this(0, 0); 25 } 26 public TestNode(double lat, double lon) { 27 this.lat = lat; 28 this.lon = lon; 29 } 30 @Override 31 public String toString() { 32 return "(" + lat + ", " + lon + "); " + tags; 33 } 34 } 35 35 36 37 38 39 40 41 42 36 public static class TestWay extends TestPrimitive { 37 public final List<TestNode> nodes = new LinkedList<TestNode>(); 38 @Override 39 public String toString() { 40 return nodes + "; " + tags; 41 } 42 } 43 43 44 45 46 47 48 49 50 44 public static class TestRelation extends TestPrimitive { 45 public final Collection<TestRelationMember> members = new LinkedList<TestRelationMember>(); 46 @Override 47 public String toString() { 48 return members + "; " + tags; 49 } 50 } 51 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 52 public static class TestRelationMember { 53 public final String role; 54 public final TestPrimitive member; 55 public TestRelationMember(String role, TestPrimitive member) { 56 this.role = role; 57 this.member = member; 58 } 59 public TestPrimitive getMember() { 60 return member; 61 } 62 public String getRole() { 63 return role; 64 } 65 @Override 66 public String toString() { 67 return role + "=" + member; 68 } 69 } 70 70 71 71 72 73 74 72 public final Collection<TestNode> nodes = new LinkedList<TestNode>(); 73 public final Collection<TestWay> ways = new LinkedList<TestWay>(); 74 public final Collection<TestRelation> relations = new LinkedList<TestRelation>(); 75 75 76 76 77 78 79 80 81 82 77 public double getLat(TestNode node) { 78 return node.lat; 79 } 80 public double getLon(TestNode node) { 81 return node.lon; 82 } 83 83 84 85 86 84 public Iterable<TestRelationMember> getMembers(TestRelation relation) { 85 return relation.members; 86 } 87 87 88 89 90 88 public Iterable<TestNode> getNodes() { 89 return nodes; 90 } 91 91 92 93 94 92 public Iterable<TestNode> getNodes(TestWay way) { 93 return way.nodes; 94 } 95 95 96 97 98 96 public Iterable<TestWay> getWays() { 97 return ways; 98 } 99 99 100 101 102 100 public Iterable<TestRelation> getRelations() { 101 return relations; 102 } 103 103 104 105 106 104 public TagGroup getTagsN(TestNode node) { 105 return new MapBasedTagGroup(node.tags); 106 } 107 107 108 109 110 108 public TagGroup getTagsW(TestWay way) { 109 return new MapBasedTagGroup(way.tags); 110 } 111 111 112 public TagGroup getTagsR(TestRelation relation) { 113 return new MapBasedTagGroup(relation.tags); 114 } 115 116 public Object getMember(TestRelationMember member) { 117 return member.getMember(); 118 } 119 120 public String getRole(TestRelationMember member) { 121 return member.getRole(); 122 } 123 124 public boolean isNMember(TestRelationMember member) { 125 return member.getMember() instanceof TestNode; 126 } 127 128 public boolean isWMember(TestRelationMember member) { 129 return member.getMember() instanceof TestWay; 130 } 131 132 public boolean isRMember(TestRelationMember member) { 133 return member.getMember() instanceof TestRelation; 134 } 112 public TagGroup getTagsR(TestRelation relation) { 113 return new MapBasedTagGroup(relation.tags); 114 } 135 115 136 void addObserver(DataSourceObserver observer) {137 // not needed for test 138 116 public Object getMember(TestRelationMember member) { 117 return member.getMember(); 118 } 139 119 140 public void deleteObserver(DataSourceObserver observer) { 141 // not needed for test 142 } 120 public String getRole(TestRelationMember member) { 121 return member.getRole(); 122 } 123 124 public boolean isNMember(TestRelationMember member) { 125 return member.getMember() instanceof TestNode; 126 } 127 128 public boolean isWMember(TestRelationMember member) { 129 return member.getMember() instanceof TestWay; 130 } 131 132 public boolean isRMember(TestRelationMember member) { 133 return member.getMember() instanceof TestRelation; 134 } 135 136 public void addObserver(DataSourceObserver observer) { 137 // not needed for test 138 } 139 140 public void deleteObserver(DataSourceObserver observer) { 141 // not needed for test 142 } 143 143 144 144 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/access/AccessRulesetReaderTest.java
r16520 r23189 22 22 public class AccessRulesetReaderTest { 23 23 24 25 24 @Test 25 public void testReadAccessRuleset_valid_classes() throws IOException { 26 26 27 28 29 27 InputStream is = new FileInputStream("plugins/graphview/test/files/accessRuleset_valid.xml"); 28 AccessRuleset ruleset = AccessRulesetReader.readAccessRuleset(is); 29 assertNotNull(ruleset); 30 30 31 31 32 32 assertEquals("vehicle", ruleset.getAccessHierarchyAncestors("vehicle").get(0)); 33 33 34 35 34 assertEquals("motor_vehicle", ruleset.getAccessHierarchyAncestors("motor_vehicle").get(0)); 35 assertEquals("vehicle", ruleset.getAccessHierarchyAncestors("motor_vehicle").get(1)); 36 36 37 38 39 37 assertEquals("bus", ruleset.getAccessHierarchyAncestors("bus").get(0)); 38 assertEquals("motor_vehicle", ruleset.getAccessHierarchyAncestors("bus").get(1)); 39 assertEquals("vehicle", ruleset.getAccessHierarchyAncestors("bus").get(2)); 40 40 41 42 41 assertEquals("bicycle", ruleset.getAccessHierarchyAncestors("bicycle").get(0)); 42 assertEquals("vehicle", ruleset.getAccessHierarchyAncestors("bicycle").get(1)); 43 43 44 44 assertFalse(ruleset.getAccessHierarchyAncestors("bus").contains("bicycle")); 45 45 46 46 assertSame(ruleset.getAccessHierarchyAncestors("boat").size(), 0); 47 47 48 48 } 49 49 50 51 50 @Test 51 public void testReadAccessRuleset_valid_basetags() throws IOException { 52 52 53 54 55 53 InputStream is = new FileInputStream("plugins/graphview/test/files/accessRuleset_valid.xml"); 54 AccessRuleset ruleset = AccessRulesetReader.readAccessRuleset(is); 55 assertNotNull(ruleset); 56 56 57 57 assertSame(2, ruleset.getBaseTags().size()); 58 58 59 60 61 62 59 assertTrue(ruleset.getBaseTags().contains(new Tag("highway", "residential"))); 60 assertTrue(ruleset.getBaseTags().contains(new Tag("highway", "cycleway"))); 61 assertFalse(ruleset.getBaseTags().contains(new Tag("building", "residential"))); 62 assertFalse(ruleset.getBaseTags().contains(new Tag("highway", "stop"))); 63 63 64 64 } 65 65 66 67 66 @Test 67 public void testReadAccessRuleset_valid_implications() throws IOException { 68 68 69 70 71 69 InputStream is = new FileInputStream("plugins/graphview/test/files/accessRuleset_valid.xml"); 70 AccessRuleset ruleset = AccessRulesetReader.readAccessRuleset(is); 71 assertNotNull(ruleset); 72 72 73 73 List<Implication> implications = ruleset.getImplications(); 74 74 75 75 assertSame(3, implications.size()); 76 76 77 78 79 80 81 77 TagGroup[] tagGroups = new TagGroup[4]; 78 tagGroups[0] = createTagGroup(new Tag("highway", "cycleway")); 79 tagGroups[1] = createTagGroup(new Tag("highway", "steps")); 80 tagGroups[2] = createTagGroup(new Tag("highway", "steps"), new Tag("escalator", "yes")); 81 tagGroups[3] = createTagGroup(new Tag("disused", "yes"), new Tag("construction", "no")); 82 82 83 84 85 86 87 83 for (Implication implication : implications) { 84 for (int i = 0; i < tagGroups.length; i++) { 85 tagGroups[i] = implication.apply(tagGroups[i]); 86 } 87 } 88 88 89 90 89 assertSame(2, tagGroups[0].size()); 90 assertTrue(tagGroups[0].contains(new Tag("bicycle", "designated"))); 91 91 92 93 92 assertSame(2, tagGroups[1].size()); 93 assertTrue(tagGroups[1].contains(new Tag("normal_steps", "yes"))); 94 94 95 96 95 assertSame(2, tagGroups[2].size()); 96 assertFalse(tagGroups[2].contains(new Tag("normal_steps", "yes"))); 97 97 98 99 100 98 assertSame(3, tagGroups[3].size()); 99 assertTrue(tagGroups[3].contains(new Tag("usable", "no"))); 100 } 101 101 102 103 104 105 106 107 108 102 private static TagGroup createTagGroup(Tag... tags) { 103 Map<String, String> tagMap = new HashMap<String, String>(); 104 for (Tag tag : tags) { 105 tagMap.put(tag.key, tag.value); 106 } 107 return new MapBasedTagGroup(tagMap); 108 } 109 109 110 110 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/property/RoadInclineTest.java
r16520 r23189 6 6 public class RoadInclineTest extends RoadPropertyTest { 7 7 8 9 8 private static void testIncline(Float expectedInclineForward, Float expectedInclineBackward, 9 String inclineString) { 10 10 11 12 13 14 11 testEvaluateW(new RoadIncline(), 12 expectedInclineForward, expectedInclineBackward, 13 new Tag("incline", inclineString)); 14 } 15 15 16 17 18 19 20 21 22 16 @Test 17 public void testEvaluate() { 18 testIncline(5f, -5f, "5 %"); 19 testIncline(9.5f, -9.5f, "9.5 %"); 20 testIncline(-2.5f, 2.5f, "-2.5%"); 21 testIncline(null, null, "steep"); 22 } 23 23 24 24 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxspeedTest.java
r21609 r23189 6 6 public class RoadMaxspeedTest extends RoadPropertyTest { 7 7 8 9 10 8 private static void testMaxspeed(float expectedMaxspeed, String maxspeedString) { 9 testEvaluateBoth(new RoadMaxspeed(), expectedMaxspeed, new Tag("maxspeed", maxspeedString)); 10 } 11 11 12 13 14 15 16 12 @Test 13 public void testEvaluate_numeric() { 14 testMaxspeed(30, "30"); 15 testMaxspeed(48.3f, "48.3"); 16 } 17 17 18 19 20 21 22 23 18 @Test 19 public void testEvaluate_kmh() { 20 testMaxspeed(50, "50 km/h"); 21 testMaxspeed(120, "120km/h"); 22 testMaxspeed(30, "30 km/h"); 23 } 24 24 25 26 27 28 29 30 25 @Test 26 public void testEvaluate_mph() { 27 testMaxspeed(72.42048f, "45 mph"); 28 testMaxspeed(64.373764f, "40mph"); 29 testMaxspeed(24.14016f, "15 mph"); 30 } 31 31 32 32 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/property/RoadPropertyTest.java
r16520 r23189 8 8 abstract public class RoadPropertyTest { 9 9 10 10 protected static <P> void testEvaluateW(RoadPropertyType<P> property, P expectedForward, P expectedBackward, Tag... wayTags) { 11 11 12 13 14 15 16 17 12 TestDataSource ds = new TestDataSource(); 13 TestDataSource.TestWay testWay = new TestDataSource.TestWay(); 14 for (Tag tag : wayTags) { 15 testWay.tags.put(tag.key, tag.value); 16 } 17 ds.ways.add(testWay); 18 18 19 20 19 assertEquals(expectedForward, property.evaluateW(testWay, true, null, ds)); 20 assertEquals(expectedBackward, property.evaluateW(testWay, false, null, ds)); 21 21 22 22 } 23 23 24 24 protected static <P> void testEvaluateN(RoadPropertyType<P> property, P expected, Tag... nodeTags) { 25 25 26 27 28 29 30 31 26 TestDataSource ds = new TestDataSource(); 27 TestDataSource.TestNode testNode = new TestDataSource.TestNode(); 28 for (Tag tag : nodeTags) { 29 testNode.tags.put(tag.key, tag.value); 30 } 31 ds.nodes.add(testNode); 32 32 33 33 RoadMaxspeed m = new RoadMaxspeed(); 34 34 35 35 assertEquals(expected, m.evaluateN(testNode, null, ds)); 36 36 37 37 } 38 38 39 40 41 42 39 protected static <P> void testEvaluateBoth(RoadPropertyType<P> property, P expected, Tag... nodeTags) { 40 testEvaluateW(property, expected, expected, nodeTags); 41 testEvaluateN(property, expected, nodeTags); 42 } 43 43 44 44 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/util/TagConditionLogicTest.java
r16520 r23189 15 15 public class TagConditionLogicTest { 16 16 17 18 17 TagGroup groupA; 18 TagGroup groupB; 19 19 20 21 22 23 24 25 26 20 @Before 21 public void setUp() { 22 Map<String, String> mapA = new HashMap<String, String>(); 23 mapA.put("key1", "value1"); 24 mapA.put("key2", "value2"); 25 mapA.put("key3", "value1"); 26 groupA = new MapBasedTagGroup(mapA); 27 27 28 29 30 31 32 28 Map<String, String> mapB = new HashMap<String, String>(); 29 mapB.put("key1", "value1"); 30 mapB.put("key4", "value4"); 31 groupB = new MapBasedTagGroup(mapB); 32 } 33 33 34 35 36 37 38 39 34 @Test 35 public void testTag() { 36 TagCondition condition = TagConditionLogic.tag(new Tag("key3", "value1")); 37 assertTrue(condition.matches(groupA)); 38 assertFalse(condition.matches(groupB)); 39 } 40 40 41 42 43 44 45 46 41 @Test 42 public void testKey() { 43 TagCondition condition = TagConditionLogic.key("key3"); 44 assertTrue(condition.matches(groupA)); 45 assertFalse(condition.matches(groupB)); 46 } 47 47 48 49 50 51 52 48 @Test 49 public void testAnd() { 50 TagCondition condition1 = TagConditionLogic.tag(new Tag("key2", "value2")); 51 TagCondition conditionAnd1a = TagConditionLogic.and(condition1); 52 TagCondition conditionAnd1b = TagConditionLogic.and(Arrays.asList(condition1)); 53 53 54 55 56 57 54 assertTrue(conditionAnd1a.matches(groupA)); 55 assertTrue(conditionAnd1b.matches(groupA)); 56 assertFalse(conditionAnd1a.matches(groupB)); 57 assertFalse(conditionAnd1b.matches(groupB)); 58 58 59 60 61 59 TagCondition condition2 = TagConditionLogic.tag(new Tag("key1", "value1")); 60 TagCondition conditionAnd2a = TagConditionLogic.and(condition1, condition2); 61 TagCondition conditionAnd2b = TagConditionLogic.and(Arrays.asList(condition1, condition2)); 62 62 63 64 65 66 63 assertTrue(conditionAnd2a.matches(groupA)); 64 assertTrue(conditionAnd2b.matches(groupA)); 65 assertFalse(conditionAnd2a.matches(groupB)); 66 assertFalse(conditionAnd2b.matches(groupB)); 67 67 68 69 70 68 TagCondition condition3 = TagConditionLogic.tag(new Tag("key4", "value4")); 69 TagCondition conditionAnd3a = TagConditionLogic.and(condition1, condition2, condition3); 70 TagCondition conditionAnd3b = TagConditionLogic.and(Arrays.asList(condition1, condition2, condition3)); 71 71 72 73 74 75 76 72 assertFalse(conditionAnd3a.matches(groupA)); 73 assertFalse(conditionAnd3b.matches(groupA)); 74 assertFalse(conditionAnd3a.matches(groupB)); 75 assertFalse(conditionAnd3b.matches(groupB)); 76 } 77 77 78 79 80 81 82 78 @Test 79 public void testOr() { 80 TagCondition condition1 = TagConditionLogic.tag(new Tag("key42", "value42")); 81 TagCondition conditionOr1a = TagConditionLogic.or(condition1); 82 TagCondition conditionOr1b = TagConditionLogic.or(Arrays.asList(condition1)); 83 83 84 85 86 87 84 assertFalse(conditionOr1a.matches(groupA)); 85 assertFalse(conditionOr1b.matches(groupA)); 86 assertFalse(conditionOr1a.matches(groupB)); 87 assertFalse(conditionOr1b.matches(groupB)); 88 88 89 90 91 89 TagCondition condition2 = TagConditionLogic.tag(new Tag("key3", "value1")); 90 TagCondition conditionOr2a = TagConditionLogic.or(condition1, condition2); 91 TagCondition conditionOr2b = TagConditionLogic.or(Arrays.asList(condition1, condition2)); 92 92 93 94 95 96 93 assertTrue(conditionOr2a.matches(groupA)); 94 assertTrue(conditionOr2b.matches(groupA)); 95 assertFalse(conditionOr2a.matches(groupB)); 96 assertFalse(conditionOr2b.matches(groupB)); 97 97 98 99 100 98 TagCondition condition3 = TagConditionLogic.tag(new Tag("key1", "value1")); 99 TagCondition conditionOr3a = TagConditionLogic.or(condition1, condition2, condition3); 100 TagCondition conditionOr3b = TagConditionLogic.or(Arrays.asList(condition1, condition2, condition3)); 101 101 102 103 104 105 106 102 assertTrue(conditionOr3a.matches(groupA)); 103 assertTrue(conditionOr3b.matches(groupA)); 104 assertTrue(conditionOr3a.matches(groupB)); 105 assertTrue(conditionOr3b.matches(groupB)); 106 } 107 107 108 109 110 111 112 113 108 @Test 109 public void testNot() { 110 TagCondition condition = TagConditionLogic.not(TagConditionLogic.key("key3")); 111 assertFalse(condition.matches(groupA)); 112 assertTrue(condition.matches(groupB)); 113 } 114 114 115 115 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/util/ValueStringParserTest.java
r20244 r23189 10 10 public class ValueStringParserTest { 11 11 12 12 /* speed */ 13 13 14 15 16 17 14 @Test 15 public void testParseSpeedDefault() { 16 assertClose(50, parseSpeed("50")); 17 } 18 18 19 20 21 22 23 19 @Test 20 public void testParseSpeedKmh() { 21 assertClose(30, parseSpeed("30 km/h")); 22 assertClose(100, parseSpeed("100km/h")); 23 } 24 24 25 26 27 28 29 25 @Test 26 public void testParseSpeedMph() { 27 assertClose(40.234f, parseSpeed("25mph")); 28 assertClose(40.234f, parseSpeed("25 mph")); 29 } 30 30 31 32 33 34 31 @Test 32 public void testParseSpeedInvalid() { 33 assertNull(parseSpeed("lightspeed")); 34 } 35 35 36 36 /* measure */ 37 37 38 39 40 41 38 @Test 39 public void testParseMeasureDefault() { 40 assertClose(3.5f, parseMeasure("3.5")); 41 } 42 42 43 44 45 46 47 43 @Test 44 public void testParseMeasureM() { 45 assertClose(2, parseMeasure("2m")); 46 assertClose(5.5f, parseMeasure("5.5 m")); 47 } 48 48 49 50 51 52 53 49 @Test 50 public void testParseMeasureKm() { 51 assertClose(1000, parseMeasure("1 km")); 52 assertClose(7200, parseMeasure("7.2km")); 53 } 54 54 55 56 57 58 55 @Test 56 public void testParseMeasureMi() { 57 assertClose(1609.344f, parseMeasure("1 mi")); 58 } 59 59 60 61 62 63 64 60 @Test 61 public void testParseMeasureFeetInches() { 62 assertClose(3.6576f, parseMeasure("12'0\"")); 63 assertClose(1.9812f, parseMeasure("6' 6\"")); 64 } 65 65 66 67 68 69 70 66 @Test 67 public void testParseMeasureInvalid() { 68 assertNull(parseMeasure("very long")); 69 assertNull(parseMeasure("6' 16\"")); 70 } 71 71 72 72 /* weight */ 73 73 74 75 76 77 74 @Test 75 public void testParseWeightDefault() { 76 assertClose(3.6f, parseWeight("3.6")); 77 } 78 78 79 80 81 82 83 79 @Test 80 public void testParseWeightT() { 81 assertClose(30, parseWeight("30t")); 82 assertClose(3.5f, parseWeight("3.5 t")); 83 } 84 84 85 86 87 88 85 @Test 86 public void testParseWeightInvalid() { 87 assertNull(parseWeight("heavy")); 88 } 89 89 90 91 92 93 94 90 private static final void assertClose(float expected, float actual) { 91 if (Math.abs(expected - actual) > 0.001) { 92 throw new AssertionError("expected " + expected + ", was " + actual); 93 } 94 } 95 95 96 96 } -
applications/editors/josm/plugins/graphview/test/org/openstreetmap/josm/plugins/graphview/core/visualisation/FloatPropertyColorSchemeTest.java
r16520 r23189 13 13 public class FloatPropertyColorSchemeTest { 14 14 15 15 private FloatPropertyColorScheme subject; 16 16 17 18 17 @Before 18 public void setUp() { 19 19 20 21 22 23 20 Map<Float, Color> colorMap = new HashMap<Float, Color>(); 21 colorMap.put( 5f, new Color( 42, 42, 42)); 22 colorMap.put(10f, new Color(100, 100, 100)); 23 colorMap.put(20f, new Color(200, 200, 200)); 24 24 25 26 25 subject = new FloatPropertyColorScheme(RoadMaxweight.class, colorMap, Color.RED); 26 } 27 27 28 29 30 31 32 28 @Test 29 public void testGetColorForValue_below() { 30 assertEquals(new Color(42, 42, 42), subject.getColorForValue(1f)); 31 assertEquals(new Color(42, 42, 42), subject.getColorForValue(5f)); 32 } 33 33 34 35 36 37 34 @Test 35 public void testGetColorForValue_above() { 36 assertEquals(new Color(200, 200, 200), subject.getColorForValue(25f)); 37 } 38 38 39 40 41 42 39 @Test 40 public void testGetColorForValue_value() { 41 assertEquals(new Color(100, 100, 100), subject.getColorForValue(10f)); 42 } 43 43 44 45 46 47 44 @Test 45 public void testGetColorForValue_interpolate() { 46 assertEquals(new Color(150, 150, 150), subject.getColorForValue(15f)); 47 } 48 48 49 49 }
Note:
See TracChangeset
for help on using the changeset viewer.