package btools.util; import java.util.Random; import java.util.HashMap; import org.junit.Assert; import org.junit.Test; public class CompactMapTest { @Test public void hashMapComparisonTest() { hashMapComparison( 0, 1 ); hashMapComparison( 1, 1 ); hashMapComparison( 2, 2 ); hashMapComparison( 3, 3 ); hashMapComparison( 4, 4 ); hashMapComparison( 5, 5 ); hashMapComparison( 7, 10 ); hashMapComparison( 8, 10 ); hashMapComparison( 10000, 20000 ); } private void hashMapComparison( int mapsize, int trycount ) { Random rand = new Random( 12345 ); HashMap hmap = new HashMap(); CompactLongMap cmap_slow = new CompactLongMap(); CompactLongMap cmap_fast = new CompactLongMap(); for( int i=0; i( cmap_slow ); cmap_fast = new FrozenLongMap( cmap_fast ); } long k = mapsize < 10 ? i : rand.nextInt( 20000 ); Long KK = new Long( k ); String s = hmap.get( KK ); boolean contained = hmap.containsKey( KK ); Assert.assertTrue( "containsKey missmatch (slow)", contained == cmap_slow.contains( k ) ); Assert.assertTrue( "containsKey missmatch (fast)", contained == cmap_fast.contains( k ) ); if ( contained ) { Assert.assertEquals( "object missmatch (fast)", s, cmap_fast.get( k ) ); Assert.assertEquals( "object missmatch (slow)", s, cmap_slow.get( k ) ); } } } }