Ignore:
Timestamp:
2016-11-17T19:58:39+01:00 (7 years ago)
Author:
michael2402
Message:

Fix #13361: Use a more consistent invalid bbox for primitives.

Patch by Gerd Petermann

Location:
trunk/test/unit/org/openstreetmap/josm/data/osm
Files:
4 edited

Legend:

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

    r10945 r11269  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertTrue;
     6
    47import org.junit.Rule;
    58import org.junit.Test;
     9import org.openstreetmap.josm.data.coor.LatLon;
    610import org.openstreetmap.josm.testutils.JOSMTestRules;
    711
     
    3135            .verify();
    3236    }
     37
     38    /**
     39     * Test LatLon constructor which might result in invalid bbox
     40     */
     41    @Test
     42    public void testLatLonConstructor() {
     43        LatLon latLon1 = new LatLon(10, 20);
     44        LatLon latLon2 = new LatLon(20, 10);
     45        BBox b1 = new BBox(latLon1, latLon2);
     46        BBox b2 = new BBox(latLon2, latLon1);
     47        assertTrue(b1.bounds(latLon1));
     48        assertTrue(b2.bounds(latLon1));
     49        assertTrue(b1.bounds(latLon2));
     50        assertTrue(b2.bounds(latLon2));
     51        assertTrue(b2.bounds(b1));
     52        assertTrue(b1.bounds(b2));
     53
     54        // invalid latlon values
     55        LatLon invalid1 = new LatLon(-190, 340);
     56        BBox b3 = new BBox(invalid1, latLon1);
     57        BBox b4 = new BBox(latLon1, invalid1);
     58        BBox b5 = new BBox(invalid1, invalid1);
     59        // what should be the result?
     60        assertTrue(b3.isValid());
     61        assertTrue(b4.isValid());
     62        assertTrue(b3.bounds(latLon1));
     63        assertTrue(b4.bounds(latLon1));
     64        assertTrue(b5.isValid());
     65        assertFalse(b5.isInWorld());
     66    }
     67
    3368}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NodeTest.java

    r10945 r11269  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertNotNull;
    67import static org.junit.Assert.assertNull;
     8import static org.junit.Assert.assertTrue;
    79
    810import org.junit.Rule;
     
    4345        assertFalse(n.isOutsideDownloadArea());
    4446    }
     47
     48    /**
     49     * Test BBox calculation with Node
     50     */
     51    @Test
     52    public void testBBox() {
     53        DataSet ds = new DataSet();
     54        Node n1 = new Node(1);
     55        Node n2 = new Node(2);
     56        Node n3 = new Node(3);
     57        Node n4 = new Node(4);
     58        n1.setIncomplete(true);
     59        n2.setCoor(new LatLon(10, 10));
     60        n3.setCoor(new LatLon(20, 20));
     61        n4.setCoor(new LatLon(90, 180));
     62        ds.addPrimitive(n1);
     63        ds.addPrimitive(n2);
     64        ds.addPrimitive(n3);
     65        ds.addPrimitive(n4);
     66
     67        assertFalse(n1.getBBox().isValid());
     68        assertTrue(n2.getBBox().isValid());
     69        assertTrue(n3.getBBox().isValid());
     70        assertTrue(n4.getBBox().isValid());
     71        BBox box1 = n1.getBBox();
     72        box1.add(n2.getCoor());
     73        assertTrue(box1.isValid());
     74        BBox box2 = n2.getBBox();
     75        box2.add(n1.getCoor());
     76        assertTrue(box2.isValid());
     77        assertEquals(box1, box2);
     78        box1.add(n3.getCoor());
     79        assertTrue(box1.isValid());
     80        assertEquals(box1.getCenter(), new LatLon(15, 15));
     81    }
    4582}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java

    r10945 r11269  
    99import java.util.Iterator;
    1010import java.util.List;
     11import java.util.Random;
    1112
    1213import org.fest.reflect.core.Reflection;
     
    175176        }
    176177        Assert.assertEquals(0, qbWays.size());
     178
     179    }
     180
     181    /**
     182     *  Add more data so that quad buckets tree has a few leaves
     183     */
     184    @Test
     185    public void testSplitsWithIncompleteData() {
     186        DataSet ds = new DataSet();
     187        long nodeId = 1;
     188        long wayId = 1;
     189        final int NUM_COMPLETE_WAYS = 300;
     190        final int NUM_INCOMPLETE_WAYS = 10;
     191        final int NUM_NODES_PER_WAY = 20;
     192        final int NUM_INCOMPLETE_NODES = 10;
     193
     194        // force splits in quad buckets
     195        Random random = new Random(31);
     196        for (int i = 0; i < NUM_COMPLETE_WAYS; i++) {
     197            Way w = new Way(wayId++);
     198            List<Node> nodes = new ArrayList<>();
     199            double center = random.nextDouble() * 10;
     200            for (int j = 0; j < NUM_NODES_PER_WAY; j++) {
     201                Node n = new Node(nodeId++);
     202                double lat = random.nextDouble() * 0.001;
     203                double lon = random.nextDouble() * 0.001;
     204                n.setCoor(new LatLon(center + lat, center + lon));
     205                nodes.add(n);
     206                ds.addPrimitive(n);
     207            }
     208            w.setNodes(nodes);
     209            ds.addPrimitive(w);
     210        }
     211        Assert.assertEquals(NUM_COMPLETE_WAYS, ds.getWays().size());
     212        Assert.assertEquals(NUM_COMPLETE_WAYS * NUM_NODES_PER_WAY, ds.getNodes().size());
     213
     214        // add some incomplete nodes
     215        List<Node> incompleteNodes = new ArrayList<>();
     216        for (int i = 0; i < NUM_INCOMPLETE_NODES; i++) {
     217            Node n = new Node(nodeId++);
     218            incompleteNodes.add(n);
     219            n.setIncomplete(true);
     220            ds.addPrimitive(n);
     221        }
     222        Assert.assertEquals(NUM_COMPLETE_WAYS * NUM_NODES_PER_WAY + NUM_INCOMPLETE_NODES, ds.getNodes().size());
     223        // add some incomplete ways
     224        List<Way> incompleteWays = new ArrayList<>();
     225        for (int i = 0; i < NUM_INCOMPLETE_WAYS; i++) {
     226            Way w = new Way(wayId++);
     227            incompleteWays.add(w);
     228            w.setIncomplete(true);
     229            ds.addPrimitive(w);
     230        }
     231        Assert.assertEquals(NUM_COMPLETE_WAYS + NUM_INCOMPLETE_WAYS, ds.getWays().size());
     232
     233        BBox planet = new BBox(-180, -90, 180, 90);
     234        // incomplete ways should not be found with search
     235        Assert.assertEquals(NUM_COMPLETE_WAYS, ds.searchWays(planet).size());
     236        // incomplete ways are only retrieved via iterator or object reference
     237        for (Way w : incompleteWays) {
     238            Assert.assertTrue(ds.getWays().contains(w));
     239        }
     240
     241        QuadBuckets<Way> qb = new QuadBuckets<>();
     242        qb.addAll(ds.getWays());
     243        int count = qb.size();
     244        Assert.assertEquals(count, ds.getWays().size());
     245        Iterator<Way> iter = qb.iterator();
     246        while (iter.hasNext()) {
     247            iter.next();
     248            iter.remove();
     249            count--;
     250            Assert.assertEquals(count, qb.size());
     251        }
     252        Assert.assertEquals(0, qb.size());
    177253    }
    178254}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java

    r10945 r11269  
    7676        Assert.assertEquals(w1.getBBox(), r1.getBBox());
    7777        Assert.assertEquals(w1.getBBox(), r2.getBBox());
     78
     79        // create incomplete node and add it to the relation, this must not change the bbox
     80        BBox oldBBox = r2.getBBox();
     81        Node n4 = new Node();
     82        n4.setIncomplete(true);
     83        ds.addPrimitive(n4);
     84        r2.addMember(new RelationMember("", n4));
     85
     86        Assert.assertEquals(oldBBox, r2.getBBox());
    7887    }
    7988
Note: See TracChangeset for help on using the changeset viewer.