src/test/java/de/blau/android/util/CollectionTest.java
/**
     * Test our Long to OsmElement hash map implementation
     */
Test our Long to OsmElement hash map implementation
Test our Long to OsmElement hash map implementation
@Test
    public void hashmap() {
        LongOsmElementMap<Node> map = new LongOsmElementMap<>(10000);
        ArrayList<Node> elements = new ArrayList<>(100000);
        for (int i = 0; i < 100000; i++) {
            elements.add(OsmElementFactory.createNode((long) (Math.random() * Long.MAX_VALUE), 1L, System.currentTimeMillis() / 1000, OsmElement.STATE_CREATED,
                    0, 0));
        }
        for (int i = 0; i < 100000; i++) {
            Node n = elements.get(i);
            map.put(n.getOsmId(), n);
        }
        for (int i = 0; i < 100000; i++) {
            assertTrue(map.containsKey(elements.get(i).getOsmId()));
        }
        List<Node> values = map.values();
        assertEquals(100000, values.size());
        int j = 0;
        for (Node n : map) {
            assertEquals(values.get(j), n); 
            j++;
        }
        for (int i = 0; i < 100000; i++) {
            assertNotNull(map.remove(elements.get(i).getOsmId()));
        }
        assertTrue(map.isEmpty());
        for (int i = 0; i < 100000; i++) {
            assertFalse(map.containsKey(elements.get(i).getOsmId()));
        }
    }
@ Test public void hashmap ( ) { LongOsmElementMap < Node > map = new LongOsmElementMap < > ( 10000 ) ; ArrayList < Node > elements = new ArrayList < > ( 100000 ) ; for ( int i = 0 ; i < 100000 ; i ++ ) { elements . add ( OsmElementFactory . createNode ( ( long ) ( Math . random ( ) * Long . MAX_VALUE ) , 1L , System . currentTimeMillis ( ) / 1000 , OsmElement . STATE_CREATED , 0 , 0 ) ) ; } for ( int i = 0 ; i < 100000 ; i ++ ) { Node n = elements . get ( i ) ; map . put ( n . getOsmId ( ) , n ) ; } for ( int i = 0 ; i < 100000 ; i ++ ) { assertTrue ( map . containsKey ( elements . get ( i ) . getOsmId ( ) ) ) ; } List < Node > values = map . values ( ) ; assertEquals ( 100000 , values . size ( ) ) ; int j = 0 ; for ( Node n : map ) { assertEquals ( values . get ( j ) , n ) ; j ++ ; } for ( int i = 0 ; i < 100000 ; i ++ ) { assertNotNull ( map . remove ( elements . get ( i ) . getOsmId ( ) ) ) ; } assertTrue ( map . isEmpty ( ) ) ; for ( int i = 0 ; i < 100000 ; i ++ ) { assertFalse ( map . containsKey ( elements . get ( i ) . getOsmId ( ) ) ) ; } }
Test our Long to OsmElement hash map implementation
Test our Long to OsmElement hash map implementation
// both should be in the same internal order