Ignore:
Timestamp:
2020-02-22T13:27:03+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #18731 - add method to search for all primitives inside a bbox (patch by taylor.smock)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java

    r15609 r15891  
    1414import org.junit.Rule;
    1515import org.junit.Test;
     16import org.openstreetmap.josm.TestUtils;
    1617import org.openstreetmap.josm.data.Bounds;
    1718import org.openstreetmap.josm.data.DataSource;
     
    6566        Assert.assertEquals("We should have found only one item.", 1, result.size());
    6667        Assert.assertTrue("The item found is relation r.", result.contains(r));
     68    }
     69
     70    /**
     71     * Unit test for {@link DataSet#searchPrimitives}
     72     */
     73    @Test
     74    public void testSearchPrimitives() {
     75        final DataSet ds = new DataSet();
     76        // null bbox => empty list
     77        Assert.assertTrue("Empty data set should produce an empty list.", ds.searchPrimitives(null).isEmpty());
     78
     79        // empty data set, any bbox => empty list
     80        BBox bbox = new BBox(new LatLon(-180, -90), new LatLon(180, 90));
     81        Assert.assertTrue("Empty data set should produce an empty list.", ds.searchPrimitives(bbox).isEmpty());
     82        // data set with elements in the given bbox => these elements
     83        Node node = new Node(LatLon.ZERO);
     84        Node node2 = new Node(new LatLon(-0.01, -0.01));
     85        Way way = TestUtils.newWay("", node, node2);
     86        Relation r = new Relation(1);
     87        RelationMember rm = new RelationMember("role", node);
     88        r.addMember(rm);
     89        way.getNodes().forEach(ds::addPrimitive);
     90        ds.addPrimitive(way);
     91        ds.addPrimitive(r);
     92        bbox = new BBox(new LatLon(-1.0, -1.0), new LatLon(1.0, 1.0));
     93        List<OsmPrimitive> result = ds.searchPrimitives(bbox);
     94        Assert.assertEquals("We should have found four items.", 4, result.size());
    6795    }
    6896
Note: See TracChangeset for help on using the changeset viewer.