@Test public void testValues() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem); map.put((double) 12, anotherItem2); map.put((double) 13, anotherItem3); map.put((double) 14, anotherItem4); map.removeKey((double) 13); List<TestClass> values = new ArrayList<TestClass>(100); map.values(values); assertEquals(3, values.size()); Collections.sort(values); assertEquals(anotherItem2, values.get(0) ); assertEquals(anotherItem4, values.get(1) ); assertEquals(anotherItem, values.get(2) ); }
@Test public void testEnsureCapacity() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); 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>(); OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem); map.put((double) 12, anotherItem2);
@Test public void testContainValue() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, item); assertTrue(map.containsValue(item)); assertFalse(map.containsValue(anotherItem)); }
@Test public void testContainsKey() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, item); assertTrue(map.containsKey((double) 11)); assertFalse(map.containsKey((double) 12)); }
@Test public void testClone() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, item); OpenDoubleObjectHashMap<TestClass> map2 = (OpenDoubleObjectHashMap<TestClass>) map.clone(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testCopy() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, item); OpenDoubleObjectHashMap<TestClass> map2 = (OpenDoubleObjectHashMap<TestClass>) map.copy(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testConstructors() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); 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 OpenDoubleObjectHashMap<TestClass>(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 OpenDoubleObjectHashMap<TestClass>(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() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, item); map.put((double) 12, anotherItem); assertSame(item, map.get((double)11) ); assertSame(null, map.get((double)0) ); }
@Test public void testPairsSortedByValue() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem5); map.put((double) 12, anotherItem4); map.put((double) 13, anotherItem3); map.put((double) 14, anotherItem2); DoubleArrayList keys = new DoubleArrayList(); List<TestClass> values = new ArrayList<TestClass>(); map.pairsSortedByValue(keys, values); assertEquals((double) 11, keys.get(3) , (double)0.000001); assertEquals(anotherItem5, values.get(3) ); assertEquals((double) 12, keys.get(2) , (double)0.000001); assertEquals(anotherItem4, values.get(2) ); assertEquals((double) 13, keys.get(1) , (double)0.000001); assertEquals(anotherItem3, values.get(1) ); assertEquals((double) 14, keys.get(0) , (double)0.000001); assertEquals(anotherItem2, values.get(0) ); }
@Test public void testPairsMatching() { DoubleArrayList keyList = new DoubleArrayList(); List<TestClass> valueList = new ArrayList<TestClass>(); OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem2); map.put((double) 12, anotherItem3); map.put((double) 13, anotherItem4); map.put((double) 14, anotherItem5); map.removeKey((double) 13); map.pairsMatching(new DoubleObjectProcedure<TestClass>() { @Override public boolean apply(double first, TestClass second) { return (first % 2) == 0; }}, keyList, valueList); keyList.sort(); Collections.sort(valueList); assertEquals(2, keyList.size()); assertEquals(2, valueList.size()); assertEquals(12, keyList.get(0) , (double)0.000001); assertEquals(14, keyList.get(1) , (double)0.000001); assertSame(anotherItem3, valueList.get(0) ); assertSame(anotherItem5, valueList.get(1) ); }
@Test public void testPairsSortedByKey() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem5); map.put((double) 12, anotherItem4); map.put((double) 13, anotherItem3); map.put((double) 14, anotherItem2); DoubleArrayList keys = new DoubleArrayList(); List<TestClass> values = new ArrayList<TestClass>(); map.pairsSortedByKey(keys, values); assertEquals(4, keys.size()); assertEquals(4, values.size()); assertEquals((double) 11, keys.get(0) , (double)0.000001); assertSame(anotherItem5, values.get(0) ); assertEquals((double) 12, keys.get(1) , (double)0.000001); assertSame(anotherItem4, values.get(1) ); assertEquals((double) 13, keys.get(2) , (double)0.000001); assertSame(anotherItem3, values.get(2) ); assertEquals((double) 14, keys.get(3) , (double)0.000001); assertSame(anotherItem2, values.get(3) ); }
@Test public void testForEachKey() { final DoubleArrayList keys = new DoubleArrayList(); OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem); map.put((double) 12, anotherItem2); map.put((double) 13, anotherItem3); map.put((double) 14, anotherItem4); map.removeKey((double) 13); map.forEachKey(new DoubleProcedure() { @Override public boolean apply(double element) { keys.add(element); return true; } }); double[] keysArray = keys.toArray(new double[keys.size()]); Arrays.sort(keysArray); assertArrayEquals(new double[] {11, 12, 14}, keysArray , (double)0.000001); }
@Test public void testClear() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); for (int i = 0; i < 100; i++) { map.put((double) i, item); assertEquals(1, map.size()); map.clear(); assertEquals(0, map.size()); assertFalse("Contains: " + i, map.containsKey((double) i)); assertSame(null, map.get((double) i)); } }
@Test public void testKeysSortedByValue() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem5); map.put((double) 12, anotherItem4); map.put((double) 13, anotherItem3); map.put((double) 14, anotherItem2); map.removeKey((double) 13); DoubleArrayList keys = new DoubleArrayList(); map.keysSortedByValue(keys); double[] keysArray = keys.toArray(new double[keys.size()]); assertArrayEquals(new double[] {14, 12, 11}, keysArray , (double)0.000001); }
@Test public void testKeys() { OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, item); map.put((double) 12, item); DoubleArrayList keys = new DoubleArrayList(); map.keys(keys); keys.sort(); assertEquals(11, keys.get(0) , (double)0.000001); assertEquals(12, keys.get(1) , (double)0.000001); DoubleArrayList 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. OpenDoubleObjectHashMap<TestClass> map = new OpenDoubleObjectHashMap<TestClass>(); map.put((double) 11, anotherItem); map.put((double) 12, anotherItem2); map.put((double) 13, anotherItem3); map.put((double) 14, anotherItem4); map.removeKey((double) 13); OpenDoubleObjectHashMap<TestClass> map2 = (OpenDoubleObjectHashMap<TestClass>) map.copy(); assertEquals(map, map2); assertTrue(map2.equals(map)); assertFalse("Hello Sailor".equals(map)); assertFalse(map.equals("hello sailor")); map2.removeKey((double) 11); assertFalse(map.equals(map2)); assertFalse(map2.equals(map)); }