-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added in Relation flattening * Formatting and removed faulty tests * PR updates * fixed check for id and added unit tests for same id
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/org/openstreetmap/atlas/geography/atlas/items/RelationFlatteningRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.openstreetmap.atlas.geography.atlas.items; | ||
|
||
import org.openstreetmap.atlas.geography.atlas.Atlas; | ||
import org.openstreetmap.atlas.utilities.testing.CoreTestRule; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas.Node; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas.Relation; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas.Relation.Member; | ||
|
||
/** | ||
* @author samuelgass | ||
*/ | ||
public class RelationFlatteningRule extends CoreTestRule | ||
{ | ||
@TestAtlas(nodes = { @Node(id = "1"), @Node(id = "2"), @Node(id = "3"), @Node(id = "4"), | ||
@Node(id = "5"), @Node(id = "6") }, relations = { | ||
|
||
@Relation(id = "6", members = { | ||
@Member(id = "1", role = "outside", type = "node") }), | ||
@Relation(id = "7", members = { | ||
@Member(id = "1", role = "outside", type = "node"), | ||
@Member(id = "2", role = "outside", type = "node"), | ||
@Member(id = "6", role = "outside", type = "node") }), | ||
@Relation(id = "8", members = { | ||
@Member(id = "4", role = "outside", type = "node"), | ||
@Member(id = "5", role = "outside", type = "node"), | ||
@Member(id = "8", role = "outside", type = "relation") }), | ||
@Relation(id = "9", members = { | ||
@Member(id = "4", role = "outside", type = "node"), | ||
@Member(id = "5", role = "outside", type = "node"), | ||
@Member(id = "7", role = "outside", type = "relation"), | ||
@Member(id = "6", role = "outside", type = "relation") }), | ||
@Relation(id = "10", members = { | ||
@Member(id = "6", role = "outside", type = "relation"), | ||
@Member(id = "3", role = "outside", type = "node"), | ||
@Member(id = "9", role = "outside", type = "relation") }), | ||
@Relation(id = "2", members = { | ||
@Member(id = "3", role = "outside", type = "node"), | ||
@Member(id = "4", role = "outside", type = "node"), | ||
@Member(id = "6", role = "outside", type = "relation") }), | ||
@Relation(id = "1", members = { | ||
@Member(id = "5", role = "outside", type = "node"), | ||
@Member(id = "2", role = "outside", type = "node"), | ||
@Member(id = "2", role = "outside", type = "relation") }) }) | ||
private Atlas atlas; | ||
|
||
public Atlas getAtlas() | ||
{ | ||
return this.atlas; | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/test/java/org/openstreetmap/atlas/geography/atlas/items/RelationFlatteningTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.openstreetmap.atlas.geography.atlas.items; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Set; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author samuelgass | ||
*/ | ||
public class RelationFlatteningTest | ||
{ | ||
private static final Logger logger = LoggerFactory.getLogger(RelationFlatteningTest.class); | ||
|
||
@Rule | ||
public final RelationFlatteningRule rule = new RelationFlatteningRule(); | ||
|
||
@Test | ||
public void testLoopingRelation() | ||
{ | ||
final Relation loopingRelation = this.rule.getAtlas().relation(8); | ||
logger.info("Looping (self-containing) Relation: {}", loopingRelation); | ||
final Set<AtlasObject> flattened = loopingRelation.flatten(); | ||
logger.info("Flattened: {}", flattened); | ||
assertEquals(2, flattened.size()); | ||
} | ||
|
||
@Test | ||
public void testNestedRelation() | ||
{ | ||
final Relation nestedRelation = this.rule.getAtlas().relation(10); | ||
logger.info("Nested Relation: {}", nestedRelation); | ||
final Set<AtlasObject> flattened = nestedRelation.flatten(); | ||
logger.info("Flattened: {}", flattened); | ||
assertEquals(6, flattened.size()); | ||
} | ||
|
||
@Test | ||
public void testNodesAndRelationsWithSameId() | ||
{ | ||
final Relation relation = this.rule.getAtlas().relation(1); | ||
logger.info("Relation containing nodes and relations with the same numeric id: {}", | ||
relation); | ||
final Set<AtlasObject> flattened = relation.flatten(); | ||
logger.info("Flattened: {}", flattened); | ||
assertEquals(5, flattened.size()); | ||
} | ||
|
||
@Test | ||
public void testShallowRelation() | ||
{ | ||
final Relation shallowRelation = this.rule.getAtlas().relation(6); | ||
logger.info("Shallow (1-node) relation: {}", shallowRelation); | ||
final Set<AtlasObject> flattened = shallowRelation.flatten(); | ||
logger.info("Flattened: {}", flattened); | ||
assertEquals(1, flattened.size()); | ||
final AtlasObject memberNode = flattened.stream().findFirst().get(); | ||
if (memberNode instanceof Node) | ||
{ | ||
assertEquals(1, ((Node) memberNode).getIdentifier()); | ||
} | ||
else | ||
{ | ||
Assert.fail("Member was not the expected type of 'Node'!"); | ||
} | ||
} | ||
} |