src/test/java/de/blau/android/util/CollectionTest.java
/**
     * Some minimal tests for our RTree implementation
     */
Some minimal tests for our RTree implementation
Some minimal tests for our RTree implementation
@Test
    public void rtree() {
        final double MAX = GeoMath.MAX_LAT_E7;
        RTree<Node> tree = new RTree<>(2, 100);
        final int NODES = 10000;
        Node[] temp = new Node[NODES];
        for (long i = 0; i < NODES; i++) {
            temp[(int) i] = OsmElementFactory.createNode(i, 1L, System.currentTimeMillis() / 1000, OsmElement.STATE_CREATED, (int) (Math.random() * MAX),
                    (int) (Math.random() * MAX));
        }
        long start = System.currentTimeMillis();
        for (long i = 0; i < NODES; i++) {
            tree.insert(temp[(int) i]);
        }
        System.out.println("Node insertion " + (System.currentTimeMillis() - start)); 
        start = System.currentTimeMillis();
        for (int i = 0; i < NODES; i++) {
            Collection<Node> result = new ArrayList<>();
            BoundingBox b = null;
            b = new BoundingBox(temp[i].getLon() - 1, temp[i].getLat() - 1, temp[i].getLon() + 1, temp[i].getLat() + 1);
            tree.query(result, b);
            assertTrue(result.contains(temp[i]));
        }
        System.out.println("Query " + (System.currentTimeMillis() - start)); 
        assertEquals(NODES, tree.count());
        start = System.currentTimeMillis();
        for (long i = 0; i < NODES; i++) {
            assertTrue(tree.contains(temp[(int) i]));
        }
        System.out.println("Contains " + (System.currentTimeMillis() - start)); 
        start = System.currentTimeMillis();
        for (long i = 0; i < NODES; i++) {
            assertTrue(tree.remove(temp[(int) i]));
        }
        System.out.println("Remove " + (System.currentTimeMillis() - start)); 
        assertEquals(0, tree.count());
    }
@ Test public void rtree ( ) { final double MAX = GeoMath . MAX_LAT_E7 ; RTree < Node > tree = new RTree < > ( 2 , 100 ) ; final int NODES = 10000 ; Node [ ] temp = new Node [ NODES ] ; for ( long i = 0 ; i < NODES ; i ++ ) { temp [ ( int ) i ] = OsmElementFactory . createNode ( i , 1L , System . currentTimeMillis ( ) / 1000 , OsmElement . STATE_CREATED , ( int ) ( Math . random ( ) * MAX ) , ( int ) ( Math . random ( ) * MAX ) ) ; } long start = System . currentTimeMillis ( ) ; for ( long i = 0 ; i < NODES ; i ++ ) { tree . insert ( temp [ ( int ) i ] ) ; } System . out . println ( "Node insertion " + ( System . currentTimeMillis ( ) - start ) ) ; start = System . currentTimeMillis ( ) ; for ( int i = 0 ; i < NODES ; i ++ ) { Collection < Node > result = new ArrayList < > ( ) ; BoundingBox b = null ; b = new BoundingBox ( temp [ i ] . getLon ( ) - 1 , temp [ i ] . getLat ( ) - 1 , temp [ i ] . getLon ( ) + 1 , temp [ i ] . getLat ( ) + 1 ) ; tree . query ( result , b ) ; assertTrue ( result . contains ( temp [ i ] ) ) ; } System . out . println ( "Query " + ( System . currentTimeMillis ( ) - start ) ) ; assertEquals ( NODES , tree . count ( ) ) ; start = System . currentTimeMillis ( ) ; for ( long i = 0 ; i < NODES ; i ++ ) { assertTrue ( tree . contains ( temp [ ( int ) i ] ) ) ; } System . out . println ( "Contains " + ( System . currentTimeMillis ( ) - start ) ) ; start = System . currentTimeMillis ( ) ; for ( long i = 0 ; i < NODES ; i ++ ) { assertTrue ( tree . remove ( temp [ ( int ) i ] ) ) ; } System . out . println ( "Remove " + ( System . currentTimeMillis ( ) - start ) ) ; assertEquals ( 0 , tree . count ( ) ) ; }
Some minimal tests for our RTree implementation
Some minimal tests for our RTree implementation
// NOSONAR // create a small bounding box around the Node and query that // NOSONAR // currently contains and remove doesn't work for nodes // NOSONAR // NOSONAR