mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-09 03:25:25 +00:00
Update test cases (#104)
* Add three test cases in HashSetValuedHashMapTest * Update test cases
This commit is contained in:
parent
c6f4b84c7d
commit
869993da97
@ -688,6 +688,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
||||
assertEquals(2, keyMultiSet.getCount("one"));
|
||||
assertEquals(2, keyMultiSet.getCount("two"));
|
||||
assertEquals(2, keyMultiSet.getCount("three"));
|
||||
assertEquals(0, keyMultiSet.getCount("conut"));
|
||||
assertEquals(6, keyMultiSet.size());
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,9 @@
|
||||
*/
|
||||
package org.apache.commons.collections4.multimap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Test;
|
||||
@ -125,6 +127,57 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
|
||||
assertNotSame(map1.hashCode(), map2.hashCode());
|
||||
}
|
||||
|
||||
public void testHashSetValueHashMap() {
|
||||
final SetValuedMap<K, V> setMap = new HashSetValuedHashMap<>(4);
|
||||
assertEquals(0, setMap.get((K) "whatever").size());
|
||||
|
||||
final Set<V> set = setMap.get((K) "A");
|
||||
set.add((V) "W");
|
||||
set.add((V) "X");
|
||||
set.add((V) "F");
|
||||
assertEquals(3, setMap.get((K) "A").size());
|
||||
}
|
||||
|
||||
public void testHashSetValueHashMap_1() {
|
||||
final MultiValuedMap<K, V> map = new ArrayListValuedHashMap<>();
|
||||
SetValuedMap<K, V> map1 = null;
|
||||
SetValuedMap<K, V> map2 = makeObject();
|
||||
SetValuedMap<K, V> map3 = null;
|
||||
|
||||
map.put((K) "A", (V) "W");
|
||||
map.put((K) "A", (V) "X");
|
||||
map.put((K) "A", (V) "F");
|
||||
map1 = new HashSetValuedHashMap<>(map);
|
||||
assertEquals(3, map1.get((K) "A").size());
|
||||
map2.put((K) "A", (V) "X");
|
||||
map2.put((K) "A", (V) "F");
|
||||
map2.put((K) "A", (V) "W");
|
||||
assertEquals(map1, map2);
|
||||
assertEquals(map1.hashCode(), map2.hashCode());
|
||||
|
||||
map.remove("A");
|
||||
map3 = new HashSetValuedHashMap<>(map);
|
||||
assertEquals("{}", map3.toString());
|
||||
}
|
||||
|
||||
public void testHashSetValuedHashMap_2(){
|
||||
final Map<K, V> map = new HashMap<>();
|
||||
SetValuedMap<K, V> map1 = null;
|
||||
SetValuedMap<K, V> map2 = null;
|
||||
|
||||
map.put((K) "A", (V) "W");
|
||||
map.put((K) "B", (V) "X");
|
||||
map.put((K) "C", (V) "F");
|
||||
map1 = new HashSetValuedHashMap<>(map);
|
||||
assertEquals(1, map1.get((K) "A").size());
|
||||
|
||||
map.remove("A");
|
||||
map.remove("B");
|
||||
map.remove("C");
|
||||
map2 = new HashSetValuedHashMap<>(map);
|
||||
assertEquals("{}", map2.toString());
|
||||
}
|
||||
|
||||
// public void testCreate() throws Exception {
|
||||
// writeExternalFormToDisk((java.io.Serializable) makeObject(),
|
||||
// "src/test/resources/data/test/HashSetValuedHashMap.emptyCollection.version4.1.obj");
|
||||
|
@ -131,6 +131,17 @@ public class TransformedMultiValuedMapTest<K, V> extends AbstractMultiValuedMapT
|
||||
assertEquals(true, trans.get((K) "C").contains(Integer.valueOf(3)));
|
||||
trans.put((K) "D", (V) "4");
|
||||
assertEquals(true, trans.get((K) "D").contains(Integer.valueOf(4)));
|
||||
|
||||
final MultiValuedMap<K, V> baseMap = new ArrayListValuedHashMap<>();
|
||||
final MultiValuedMap<K, V> transMap = TransformedMultiValuedMap
|
||||
.transformedMap(
|
||||
baseMap,
|
||||
null,
|
||||
(Transformer<? super V, ? extends V>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||
assertEquals(0, transMap.size());
|
||||
transMap.put((K) "D", (V) "4");
|
||||
assertEquals(1, transMap.size());
|
||||
assertEquals(true, transMap.get((K) "D").contains(Integer.valueOf(4)));
|
||||
}
|
||||
|
||||
// public void testCreate() throws Exception {
|
||||
|
Loading…
x
Reference in New Issue
Block a user