Changeset 3476 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2010-08-29T12:58:38+02:00 (14 years ago)
Author:
jttt
Message:

QuadBuckets optimization - keep children as fields instead of 4-item array

File:
1 edited

Legend:

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

    r3166 r3476  
    44import java.io.FileInputStream;
    55import java.util.ArrayList;
     6import java.util.Collection;
     7import java.util.Iterator;
    68import java.util.List;
    79
     10import org.fest.reflect.core.Reflection;
     11import org.fest.reflect.reference.TypeRef;
    812import org.junit.Assert;
    913import org.junit.Test;
     
    2024        List<Way> allWays = new ArrayList<Way>(ds.getWays());
    2125        List<Relation> allRelations = new ArrayList<Relation>(ds.getRelations());
     26
     27        QuadBuckets<Node> nodes = Reflection.field("nodes").ofType(new TypeRef<QuadBuckets<Node>>() {}).in(ds).get();
     28        QuadBuckets<Way> ways = Reflection.field("ways").ofType(new TypeRef<QuadBuckets<Way>>() {}).in(ds).get();
     29        Collection<Relation> relations = Reflection.field("relations").ofType(new TypeRef<Collection<Relation>>() {}).in(ds).get();
     30
     31        int expectedCount = allNodes.size();
    2232        for (OsmPrimitive o: allNodes) {
    2333            ds.removePrimitive(o);
     34            checkIterator(nodes, --expectedCount);
    2435        }
     36        expectedCount = allWays.size();
    2537        for (OsmPrimitive o: allWays) {
    2638            ds.removePrimitive(o);
     39            checkIterator(ways, --expectedCount);
    2740        }
    2841        for (OsmPrimitive o: allRelations) {
    2942            ds.removePrimitive(o);
    3043        }
     44        Assert.assertTrue(nodes.isEmpty());
     45        Assert.assertTrue(ways.isEmpty());
     46        Assert.assertTrue(relations.isEmpty());
     47    }
    3148
    32         Assert.assertTrue(ds.getNodes().isEmpty());
    33         Assert.assertTrue(ds.getWays().isEmpty());
    34         Assert.assertTrue(ds.getRelations().isEmpty());
     49    private void checkIterator(Collection<? extends OsmPrimitive> col, int expectedCount) {
     50        int count = 0;
     51        Iterator<? extends OsmPrimitive> it = col.iterator();
     52        while (it.hasNext()) {
     53            count++;
     54            it.next();
     55        }
     56        Assert.assertEquals(expectedCount, count);
    3557    }
    3658
Note: See TracChangeset for help on using the changeset viewer.