[52] | 1 | package org.openstreetmap.josm.test;
|
---|
| 2 |
|
---|
| 3 | import junit.framework.TestCase;
|
---|
| 4 |
|
---|
| 5 | import org.openstreetmap.josm.data.GeoPoint;
|
---|
| 6 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
| 7 | import org.openstreetmap.josm.data.osm.LineSegment;
|
---|
| 8 | import org.openstreetmap.josm.data.osm.Node;
|
---|
[57] | 9 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[52] | 10 | import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
|
---|
[57] | 11 | import org.openstreetmap.josm.test.framework.Bug;
|
---|
[52] | 12 | import org.openstreetmap.josm.test.framework.DataSetTestCaseHelper;
|
---|
| 13 |
|
---|
| 14 | public class MergeVisitorTest extends TestCase {
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Merge of an old line segment with a new one. This should
|
---|
| 19 | * be mergable (if the nodes matches).
|
---|
| 20 | */
|
---|
| 21 | public void testMergeOldLineSegmentsWithNew() {
|
---|
| 22 | DataSet ds = new DataSet();
|
---|
[57] | 23 | Node[] n = createNodes(ds, 2);
|
---|
| 24 | LineSegment ls1 = DataSetTestCaseHelper.createLineSegment(ds, n[0], n[1]);
|
---|
[52] | 25 | ls1.id = 3;
|
---|
| 26 |
|
---|
[66] | 27 | Node newnode = new Node(new GeoPoint(n[1].coor.lat, n[1].coor.lon));
|
---|
[57] | 28 | LineSegment newls = new LineSegment(n[0], newnode);
|
---|
[52] | 29 |
|
---|
| 30 | MergeVisitor v = new MergeVisitor(ds);
|
---|
| 31 | v.visit(newls);
|
---|
| 32 | assertEquals("line segment should have been merged.", 1, ds.lineSegments.size());
|
---|
| 33 | }
|
---|
[57] | 34 |
|
---|
| 35 | /**
|
---|
| 36 | * Nodes beeing merged are equal but not the same.
|
---|
| 37 | */
|
---|
| 38 | @Bug(54)
|
---|
| 39 | public void testEqualNotSame() {
|
---|
| 40 | // create a dataset with line segment a-b
|
---|
| 41 | DataSet ds = new DataSet();
|
---|
| 42 | Node n[] = createNodes(ds, 2);
|
---|
| 43 | LineSegment ls1 = DataSetTestCaseHelper.createLineSegment(ds, n[0], n[1]);
|
---|
| 44 | ls1.id = 1;
|
---|
| 45 |
|
---|
| 46 | // create an other dataset with line segment a'-c (a' is equal, but not same to a)
|
---|
| 47 | DataSet ds2 = new DataSet();
|
---|
| 48 | Node n2[] = createNodes(ds2, 2);
|
---|
| 49 | n2[0].coor = new GeoPoint(n[0].coor.lat, n[0].coor.lon);
|
---|
| 50 | n2[1].id = 42;
|
---|
| 51 | LineSegment ls2 = DataSetTestCaseHelper.createLineSegment(ds, n2[0], n2[1]);
|
---|
| 52 |
|
---|
| 53 | MergeVisitor v = new MergeVisitor(ds);
|
---|
| 54 | for (OsmPrimitive osm : ds2.allPrimitives())
|
---|
| 55 | osm.visit(v);
|
---|
| 56 | v.fixReferences();
|
---|
| 57 |
|
---|
[66] | 58 | assertSame(ls1.from, ls2.from);
|
---|
[57] | 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Create that amount of nodes and add them to the dataset. The id will be 1,2,3,4...
|
---|
| 64 | * @param amount Number of nodes to create.
|
---|
| 65 | * @return The created nodes.
|
---|
| 66 | */
|
---|
| 67 | private Node[] createNodes(DataSet ds, int amount) {
|
---|
| 68 | Node[] nodes = new Node[amount];
|
---|
| 69 | for (int i = 0; i < amount; ++i) {
|
---|
| 70 | nodes[i] = DataSetTestCaseHelper.createNode(ds);
|
---|
| 71 | nodes[i].id = i+1;
|
---|
| 72 | }
|
---|
| 73 | return nodes;
|
---|
| 74 | }
|
---|
[52] | 75 | }
|
---|