public Int2IntHashMapNotAvoidingAllocationTest() { super(new Int2IntHashMap(MIN_CAPACITY, Hashing.DEFAULT_LOAD_FACTOR, MISSING_VALUE, false)); }
public Int2IntHashMapTest() { this (new Int2IntHashMap(MISSING_VALUE)); }
@Test(expected = IllegalArgumentException.class) public void shouldNotSupportLoadFactorOfGreaterThanOne() { new Int2IntHashMap(4, 2, 0); }
@Test(expected = IllegalArgumentException.class) public void shouldNotSupportLoadFactorOfGreaterThanOne() { new Int2IntHashMap(4, 2, 0); }
@Test(expected = IllegalArgumentException.class) public void shouldNotSupportLoadFactorOfOne() { new Int2IntHashMap(4, 1, 0); }
@Test(expected = IllegalArgumentException.class) public void shouldNotSupportLoadFactorOfOne() { new Int2IntHashMap(4, 1, 0); }
public Map<Integer, Integer> create(final Object... entries) { final Int2IntHashMap map = new Int2IntHashMap( entries.length * 2, Hashing.DEFAULT_LOAD_FACTOR, -1, false); for (final Object o : entries) { @SuppressWarnings("unchecked") final Map.Entry<Integer, Integer> e = (Map.Entry<Integer, Integer>)o; map.put(e.getKey(), e.getValue()); } return map; }
@Test public void computeIfAbsentUsingInterface() { final Map<Integer, Integer> map = new Int2IntHashMap(-1); final int key = 0; final int result = map.computeIfAbsent(key, (k) -> k); assertEquals(key, result); }
@Test public void emptyMapsShouldHaveEqualHashCodes() { assertHashcodeEquals(map, new Int2IntHashMap(MISSING_VALUE)); assertHashcodeEquals(map, new HashMap<Integer, Integer>()); }
@Test public void emptyMapsShouldBeEqual() { assertEquals(map, new Int2IntHashMap(MISSING_VALUE)); assertEquals(map, new HashMap<Integer, Integer>()); }
@Test public void correctSizeAfterRehash() { final Int2IntHashMap map = new Int2IntHashMap(16, 0.6f, -1); IntStream.range(1, 17).forEach((i) -> map.put(i, i)); assertEquals("Map has correct size", 16, map.size()); final List<Integer> keys = new ArrayList<>(map.keySet()); keys.forEach(map::remove); assertTrue("Map isn't empty", map.isEmpty()); }
@Test public void correctSizeAfterRehash() { final Int2IntHashMap map = new Int2IntHashMap(16, 0.6f, -1); IntStream.range(1, 17).forEach((i) -> map.put(i, i)); assertEquals("Map has correct size", 16, map.size()); final List<Integer> keys = new ArrayList<>(map.keySet()); keys.forEach(map::remove); assertTrue("Map isn't empty", map.isEmpty()); }
@Test public void computeIfAbsentUsingImplementation() { final Int2IntHashMap int2IntHashMap = new Int2IntHashMap(-1); final int key = 0; final int result = int2IntHashMap.computeIfAbsent(key, (k) -> k); assertEquals(key, result); }
@Test public void shouldEqualPrimitiveMapWithSameContents() { final Int2IntHashMap otherMap = new Int2IntHashMap(MISSING_VALUE); addValues(map); addValues(otherMap); assertEquals(map, otherMap); }
@Test public void shouldNotEqualPrimitiveMapWithDifferentContents() { final Int2IntHashMap otherMap = new Int2IntHashMap(MISSING_VALUE); addValues(map); addAValue(otherMap); assertNotEquals(map, otherMap); }
@Test public void shouldNotHaveEqualHashcodePrimitiveMapWithDifferentContents() { final Int2IntHashMap otherMap = new Int2IntHashMap(MISSING_VALUE); addValues(map); addAValue(otherMap); assertHashcodeNotEquals(map, otherMap); }
@Test public void shouldEqualPrimitiveMapWithSameContentsAndDifferentMissingValue() { final Int2IntHashMap otherMap = new Int2IntHashMap(-2); addValues(map); addValues(otherMap); assertEquals(map, otherMap); }
@Test public void shouldHaveEqualHashcodePrimitiveMapWithSameContentsAndDifferentMissingValue() { final Int2IntHashMap otherMap = new Int2IntHashMap(-2); addValues(map); addValues(otherMap); assertHashcodeEquals(map, otherMap); }
@Test public void shouldHaveEqualHashcodePrimitiveMapWithSameContents() { final Int2IntHashMap otherMap = new Int2IntHashMap(MISSING_VALUE); addValues(map); addValues(otherMap); assertHashcodeEquals(map, otherMap); }
@Test public void shouldIterateEntriesBySpecialisedType() { final Map<Integer, Integer> expected = new HashMap<>(); final Int2IntHashMap map = new Int2IntHashMap(Integer.MIN_VALUE); IntStream.range(1, 10).forEachOrdered((i) -> { map.put(i, -i); expected.put(i, -i); }); final Map<Integer, Integer> actual = new HashMap<>(); final Int2IntHashMap.EntryIterator iter = map.entrySet().iterator(); while (iter.hasNext()) { iter.next(); actual.put(iter.getIntKey(), iter.getIntValue()); } assertEquals(expected, actual); }