Add test for merging addresses/buildings

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head v1.1.2
Taylor Smock 2020-01-15 16:43:14 -07:00
rodzic a2bde9603d
commit a4f0f65cd2
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
1 zmienionych plików z 98 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,98 @@
package org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.RelationMember;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
public class MergeBuildingAddressTest {
/**
* Setup test.
*/
@Rule
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public JOSMTestRules rule = new JOSMTestRules().projection();
@Test
public void testSingleAddress() {
DataSet ds = new DataSet();
Node addr = new Node(new LatLon(0, 0));
ds.addPrimitive(addr);
addr.put("addr:housenumber", "1");
MergeBuildingAddress conflation = new MergeBuildingAddress(ds);
assertNull(conflation.getCommand(Collections.singletonList(addr)));
final double square = 0.0001;
Way way = TestUtils.newWay("", new Node(new LatLon(-square, -square)), new Node(new LatLon(-square, square)),
new Node(new LatLon(square, square)), new Node(new LatLon(square, -square)));
way.getNodes().forEach(ds::addPrimitive);
ds.addPrimitive(way);
way.addNode(way.firstNode());
assertNull(conflation.getCommand(Collections.singletonList(addr)));
way.put("building", "yes");
Command command = conflation.getCommand(Collections.singletonList(addr));
command.executeCommand();
assertEquals("1", way.get("addr:housenumber"));
command.undoCommand();
way.remove("building");
Relation multipolygon = new Relation();
multipolygon.addMember(new RelationMember("outer", way));
multipolygon.put("type", "multipolygon");
ds.addPrimitive(multipolygon);
assertNull(conflation.getCommand(Collections.singletonList(addr)));
multipolygon.put("building", "yes");
command = conflation.getCommand(Collections.singletonList(addr));
command.executeCommand();
assertEquals("1", multipolygon.get("addr:housenumber"));
command.undoCommand();
}
@Test
public void testMultiAddress() {
DataSet ds = new DataSet();
Node addr = new Node(new LatLon(0, 0));
Node addr2 = new Node(new LatLon(0.00005, 0.00005));
ds.addPrimitive(addr);
ds.addPrimitive(addr2);
addr.put("addr:housenumber", "1");
addr2.put("addr:housenumber", "2");
addr.put("addr:street", "Test");
addr2.put("addr:street", "Test");
MergeBuildingAddress conflation = new MergeBuildingAddress(ds);
assertNull(conflation.getCommand(Collections.singletonList(addr)));
final double square = 0.0001;
Way way = TestUtils.newWay("", new Node(new LatLon(-square, -square)), new Node(new LatLon(-square, square)),
new Node(new LatLon(square, square)), new Node(new LatLon(square, -square)));
way.getNodes().forEach(ds::addPrimitive);
ds.addPrimitive(way);
way.addNode(way.firstNode());
assertNull(conflation.getCommand(Collections.singletonList(addr)));
way.put("building", "yes");
assertNull(conflation.getCommand(Collections.singletonList(addr)));
way.remove("building");
Relation multipolygon = new Relation();
multipolygon.addMember(new RelationMember("outer", way));
multipolygon.put("type", "multipolygon");
ds.addPrimitive(multipolygon);
assertNull(conflation.getCommand(Collections.singletonList(addr)));
multipolygon.put("building", "yes");
assertNull(conflation.getCommand(Collections.singletonList(addr)));
}
}