@Test public void testEnsureCapacity() { OpenIntByteHashMap map = new OpenIntByteHashMap(); int prime = PrimeFinder.nextPrime(907); map.ensureCapacity(prime); int[] capacity = new int[1]; double[] minLoadFactor = new double[1]; double[] maxLoadFactor = new double[1]; map.getInternalFactors(capacity, minLoadFactor, maxLoadFactor); assertEquals(prime, capacity[0]); }
@Test public void testForEachPair() { final List<Pair> pairs = new ArrayList<Pair>(); OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23);
@Test public void testContainsKey() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); assertTrue(map.containsKey((int) 11)); assertFalse(map.containsKey((int) 12)); }
@Test public void testContainValue() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); assertTrue(map.containsValue((byte) 22)); assertFalse(map.containsValue((byte) 23)); }
@Test public void testClone() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); OpenIntByteHashMap map2 = (OpenIntByteHashMap) map.clone(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testCopy() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); OpenIntByteHashMap map2 = (OpenIntByteHashMap) map.copy(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testConstructors() { OpenIntByteHashMap map = new OpenIntByteHashMap(); int[] capacity = new int[1]; double[] minLoadFactor = new double[1]; double[] maxLoadFactor = new double[1]; map.getInternalFactors(capacity, minLoadFactor, maxLoadFactor); assertEquals(AbstractSet.DEFAULT_CAPACITY, capacity[0]); assertEquals(AbstractSet.DEFAULT_MAX_LOAD_FACTOR, maxLoadFactor[0], 0.001); assertEquals(AbstractSet.DEFAULT_MIN_LOAD_FACTOR, minLoadFactor[0], 0.001); int prime = PrimeFinder.nextPrime(907); map = new OpenIntByteHashMap(prime); map.getInternalFactors(capacity, minLoadFactor, maxLoadFactor); assertEquals(prime, capacity[0]); assertEquals(AbstractSet.DEFAULT_MAX_LOAD_FACTOR, maxLoadFactor[0], 0.001); assertEquals(AbstractSet.DEFAULT_MIN_LOAD_FACTOR, minLoadFactor[0], 0.001); map = new OpenIntByteHashMap(prime, 0.4, 0.8); map.getInternalFactors(capacity, minLoadFactor, maxLoadFactor); assertEquals(prime, capacity[0]); assertEquals(0.4, minLoadFactor[0], 0.001); assertEquals(0.8, maxLoadFactor[0], 0.001); }
@Test public void testGet() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); assertEquals(22, map.get((int)11) ); assertEquals(0, map.get((int)0) ); }
@Test public void testClear() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); assertEquals(1, map.size()); map.clear(); assertEquals(0, map.size()); assertEquals(0, map.get((int) 11), 0.0000001); }
@Test public void testForEachKey() { final IntArrayList keys = new IntArrayList(); OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); map.forEachKey(new IntProcedure() { @Override public boolean apply(int element) { keys.add(element); return true; } }); int[] keysArray = keys.toArray(new int[keys.size()]); Arrays.sort(keysArray); assertArrayEquals(new int[] {11, 12, 14}, keysArray ); }
@Test public void testAdjustOrPutValue() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.adjustOrPutValue((int)11, (byte)1, (byte)3); assertEquals(25, map.get((int)11) ); map.adjustOrPutValue((int)15, (byte)1, (byte)3); assertEquals(1, map.get((int)15) ); }
@Test public void testKeysSortedByValue() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); IntArrayList keys = new IntArrayList(); map.keysSortedByValue(keys); int[] keysArray = keys.toArray(new int[keys.size()]); assertArrayEquals(new int[] {11, 12, 14}, keysArray ); }
@Test public void testKeys() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 22); IntArrayList keys = new IntArrayList(); map.keys(keys); keys.sort(); assertEquals(11, keys.get(0) ); assertEquals(12, keys.get(1) ); IntArrayList k2 = map.keys(); k2.sort(); assertEquals(keys, k2); }
@Test public void testEquals() { // since there are no other subclasses of // Abstractxxx available, we have to just test the // obvious. OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); OpenIntByteHashMap map2 = (OpenIntByteHashMap) map.copy(); assertEquals(map, map2); assertTrue(map2.equals(map)); assertFalse("Hello Sailor".equals(map)); assertFalse(map.equals("hello sailor")); map2.removeKey((int) 11); assertFalse(map.equals(map2)); assertFalse(map2.equals(map)); }
@Test public void testValues() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); ByteArrayList values = new ByteArrayList(100); map.values(values); assertEquals(3, values.size()); values.sort(); assertEquals(22, values.get(0) ); assertEquals(23, values.get(1) ); assertEquals(25, values.get(2) ); }
@Test public void testPairsMatching() { IntArrayList keyList = new IntArrayList(); ByteArrayList valueList = new ByteArrayList(); OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); map.pairsMatching(new IntByteProcedure() { @Override public boolean apply(int first, byte second) { return (first % 2) == 0; }}, keyList, valueList); keyList.sort(); valueList.sort(); assertEquals(2, keyList.size()); assertEquals(2, valueList.size()); assertEquals(12, keyList.get(0) ); assertEquals(14, keyList.get(1) ); assertEquals(23, valueList.get(0) ); assertEquals(25, valueList.get(1) ); }
@Test public void testPairsSortedByKey() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 100); map.put((int) 12, (byte) 70);