/** * Tests that nHMWES makes hash maps large enough that adding the expected number of elements * won't cause a rehash. * * <p>As of jdk7u40, HashMap has an empty-map optimization. The argument to new HashMap(int) is * noted, but the initial table is a zero-length array. * * <p>This test may fail miserably on non-OpenJDK environments... */ @GwtIncompatible // reflection @AndroidIncompatible // relies on assumptions about OpenJDK public void testNewHashMapWithExpectedSize_wontGrow() throws Exception { // before jdk7u40: creates one-bucket table // after jdk7u40: creates empty table assertTrue(bucketsOf(Maps.newHashMapWithExpectedSize(0)) <= 1); for (int size = 1; size < 200; size++) { assertWontGrow( size, Maps.newHashMapWithExpectedSize(size), Maps.newHashMapWithExpectedSize(size)); } }
/** Same test as above but for newLinkedHashMapWithExpectedSize */ @GwtIncompatible // reflection @AndroidIncompatible // relies on assumptions about OpenJDK public void testNewLinkedHashMapWithExpectedSize_wontGrow() throws Exception { assertTrue(bucketsOf(Maps.newLinkedHashMapWithExpectedSize(0)) <= 1); for (int size = 1; size < 200; size++) { assertWontGrow( size, Maps.newLinkedHashMapWithExpectedSize(size), Maps.newLinkedHashMapWithExpectedSize(size)); } }
/** * Tests that nHMWES makes hash maps large enough that adding the expected * number of elements won't cause a rehash. * * As of jdk7u40, HashMap has an empty-map optimization. The argument to * new HashMap(int) is noted, but the initial table is a zero-length array. * * This test may fail miserably on non-OpenJDK environments... */ @GwtIncompatible // reflection @AndroidIncompatible // relies on assumptions about OpenJDK public void testNewHashMapWithExpectedSize_wontGrow() throws Exception { // before jdk7u40: creates one-bucket table // after jdk7u40: creates empty table assertTrue(bucketsOf(Maps.newHashMapWithExpectedSize(0)) <= 1); for (int size = 1; size < 200; size++) { assertWontGrow(size, Maps.newHashMapWithExpectedSize(size), Maps.newHashMapWithExpectedSize(size)); } }
/** * Same test as above but for newLinkedHashMapWithExpectedSize */ @GwtIncompatible // reflection @AndroidIncompatible // relies on assumptions about OpenJDK public void testNewLinkedHashMapWithExpectedSize_wontGrow() throws Exception { assertTrue(bucketsOf(Maps.newLinkedHashMapWithExpectedSize(0)) <= 1); for (int size = 1; size < 200; size++) { assertWontGrow(size, Maps.newLinkedHashMapWithExpectedSize(size), Maps.newLinkedHashMapWithExpectedSize(size)); } }