ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/HashMap/WhiteBoxResizeTest.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/HashMap/WhiteBoxResizeTest.java (file contents):
Revision 1.1 by jsr166, Tue Dec 18 20:21:24 2018 UTC vs.
Revision 1.2 by jsr166, Wed Dec 19 14:48:32 2018 UTC

# Line 27 | Line 27 | import java.lang.invoke.MethodHandles;
27   import java.lang.invoke.MethodType;
28   import java.lang.invoke.VarHandle;
29   import java.util.HashMap;
30 + import java.util.LinkedHashMap;
31 + import java.util.List;
32   import java.util.Map;
33 + import java.util.concurrent.ThreadLocalRandom;
34 + import java.util.function.Supplier;
35   import java.util.stream.IntStream;
36  
37   import static java.util.stream.Collectors.toMap;
# Line 42 | Line 46 | import static org.testng.Assert.assertNu
46   * @run testng WhiteBoxResizeTest
47   */
48   public class WhiteBoxResizeTest {
49 +    final ThreadLocalRandom rnd = ThreadLocalRandom.current();
50      final MethodHandle TABLE_SIZE_FOR;
51      final VarHandle THRESHOLD;
52      final VarHandle TABLE;
# Line 91 | Line 96 | public class WhiteBoxResizeTest {
96      }
97  
98      @Test
99 <    public void capacityTest() {
100 <        HashMap<Integer, Integer> map = new HashMap<>();
99 >    public void capacityTestDefaultConstructor() {
100 >        capacityTestDefaultConstructor(new HashMap<>());
101 >        capacityTestDefaultConstructor(new LinkedHashMap<>());
102 >    }
103 >
104 >    void capacityTestDefaultConstructor(HashMap<Integer, Integer> map) {
105          assertNull(table(map));
106  
107          map.put(1, 1);
108 <        assertEquals(capacity(map), 16);
108 >        assertEquals(capacity(map), 16); // default initial capacity
109  
110          map.putAll(IntStream.range(0, 64).boxed().collect(toMap(i -> i, i -> i)));
111          assertEquals(capacity(map), 128);
112      }
113 +
114 +    @Test
115 +    public void capacityTestInitialCapacity() {
116 +        int initialCapacity = rnd.nextInt(1, 256);
117 +        List<Supplier<HashMap<Integer, Integer>>> suppliers = List.of(
118 +            () -> new HashMap<>(initialCapacity),
119 +            () -> new HashMap<>(initialCapacity, 0.75f),
120 +            () -> new LinkedHashMap<>(initialCapacity),
121 +            () -> new LinkedHashMap<>(initialCapacity, 0.75f));
122 +
123 +        for (Supplier<HashMap<Integer, Integer>> supplier : suppliers) {
124 +            HashMap<Integer, Integer> map = supplier.get();
125 +            assertNull(table(map));
126 +
127 +            map.put(1, 1);
128 +            assertEquals(capacity(map), tableSizeFor(initialCapacity));
129 +        }
130 +    }
131   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines