@Test public void testEnsureCapacity() { OpenByteShortHashMap map = new OpenByteShortHashMap(); 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 testCopy() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); OpenByteShortHashMap map2 = (OpenByteShortHashMap) map.copy(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testContainValue() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); assertTrue(map.containsValue((short) 22)); assertFalse(map.containsValue((short) 23)); }
@Test public void testForEachPair() { final List<Pair> pairs = new ArrayList<Pair>(); OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23);
@Test public void testClone() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); OpenByteShortHashMap map2 = (OpenByteShortHashMap) map.clone(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testContainsKey() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); assertTrue(map.containsKey((byte) 11)); assertFalse(map.containsKey((byte) 12)); }
@Test public void testConstructors() { OpenByteShortHashMap map = new OpenByteShortHashMap(); 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 OpenByteShortHashMap(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 OpenByteShortHashMap(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() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); assertEquals(22, map.get((byte)11) ); assertEquals(0, map.get((byte)0) ); }
@Test public void testClear() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); assertEquals(1, map.size()); map.clear(); assertEquals(0, map.size()); assertEquals(0, map.get((byte) 11), 0.0000001); }
@Test public void testForEachKey() { final ByteArrayList keys = new ByteArrayList(); OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); map.put((byte) 13, (short) 24); map.put((byte) 14, (short) 25); map.removeKey((byte) 13); map.forEachKey(new ByteProcedure() { @Override public boolean apply(byte element) { keys.add(element); return true; } }); byte[] keysArray = keys.toArray(new byte[keys.size()]); Arrays.sort(keysArray); assertArrayEquals(new byte[] {11, 12, 14}, keysArray ); }
@Test public void testAdjustOrPutValue() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); map.put((byte) 13, (short) 24); map.put((byte) 14, (short) 25); map.adjustOrPutValue((byte)11, (short)1, (short)3); assertEquals(25, map.get((byte)11) ); map.adjustOrPutValue((byte)15, (short)1, (short)3); assertEquals(1, map.get((byte)15) ); }
@Test public void testKeysSortedByValue() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); map.put((byte) 13, (short) 24); map.put((byte) 14, (short) 25); map.removeKey((byte) 13); ByteArrayList keys = new ByteArrayList(); map.keysSortedByValue(keys); byte[] keysArray = keys.toArray(new byte[keys.size()]); assertArrayEquals(new byte[] {11, 12, 14}, keysArray ); }
@Test public void testKeys() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 22); ByteArrayList keys = new ByteArrayList(); map.keys(keys); keys.sort(); assertEquals(11, keys.get(0) ); assertEquals(12, keys.get(1) ); ByteArrayList 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. OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); map.put((byte) 13, (short) 24); map.put((byte) 14, (short) 25); map.removeKey((byte) 13); OpenByteShortHashMap map2 = (OpenByteShortHashMap) map.copy(); assertEquals(map, map2); assertTrue(map2.equals(map)); assertFalse("Hello Sailor".equals(map)); assertFalse(map.equals("hello sailor")); map2.removeKey((byte) 11); assertFalse(map.equals(map2)); assertFalse(map2.equals(map)); }
@Test public void testValues() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); map.put((byte) 13, (short) 24); map.put((byte) 14, (short) 25); map.removeKey((byte) 13); ShortArrayList values = new ShortArrayList(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() { ByteArrayList keyList = new ByteArrayList(); ShortArrayList valueList = new ShortArrayList(); OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 22); map.put((byte) 12, (short) 23); map.put((byte) 13, (short) 24); map.put((byte) 14, (short) 25); map.removeKey((byte) 13); map.pairsMatching(new ByteShortProcedure() { @Override public boolean apply(byte first, short 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() { OpenByteShortHashMap map = new OpenByteShortHashMap(); map.put((byte) 11, (short) 100); map.put((byte) 12, (short) 70);