fixed funky line feeds and indicated that MultiHashMap is new to
Collections 2.x git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130584 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d5ab2edce1
commit
3c53553bb2
|
@ -1,228 +1,233 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.2 2002/02/22 02:18:50 mas Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.3 2002/02/26 00:13:37 morgand Exp $
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
* $Date: 2002/02/22 02:18:50 $
|
* $Date: 2002/02/26 00:13:37 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
*
|
*
|
||||||
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
|
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in
|
* notice, this list of conditions and the following disclaimer in
|
||||||
* the documentation and/or other materials provided with the
|
* the documentation and/or other materials provided with the
|
||||||
* distribution.
|
* distribution.
|
||||||
*
|
*
|
||||||
* 3. The end-user documentation included with the redistribution, if
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
* any, must include the following acknowlegement:
|
* any, must include the following acknowlegement:
|
||||||
* "This product includes software developed by the
|
* "This product includes software developed by the
|
||||||
* Apache Software Foundation (http://www.apache.org/)."
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
* Alternately, this acknowlegement may appear in the software itself,
|
* Alternately, this acknowlegement may appear in the software itself,
|
||||||
* if and wherever such third-party acknowlegements normally appear.
|
* if and wherever such third-party acknowlegements normally appear.
|
||||||
*
|
*
|
||||||
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
* Foundation" must not be used to endorse or promote products derived
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
* from this software without prior written permission. For written
|
* from this software without prior written permission. For written
|
||||||
* permission, please contact apache@apache.org.
|
* permission, please contact apache@apache.org.
|
||||||
*
|
*
|
||||||
* 5. Products derived from this software may not be called "Apache"
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
* nor may "Apache" appear in their names without prior written
|
* nor may "Apache" appear in their names without prior written
|
||||||
* permission of the Apache Group.
|
* permission of the Apache Group.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* This software consists of voluntary contributions made by many
|
* This software consists of voluntary contributions made by many
|
||||||
* individuals on behalf of the Apache Software Foundation. For more
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
* information on the Apache Software Foundation, please see
|
* information on the Apache Software Foundation, please see
|
||||||
* <http://www.apache.org/>.
|
* <http://www.apache.org/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.commons.collections;
|
package org.apache.commons.collections;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit Tests for <code>MultiHashMap</code>.
|
* Unit Tests for <code>MultiHashMap</code>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TestMultiHashMap extends TestMap
|
public class TestMultiHashMap extends TestMap
|
||||||
{
|
{
|
||||||
public TestMultiHashMap(String testName)
|
public TestMultiHashMap(String testName)
|
||||||
{
|
{
|
||||||
super(testName);
|
super(testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite()
|
public static Test suite()
|
||||||
{
|
{
|
||||||
return new TestSuite(TestMultiHashMap.class);
|
return new TestSuite(TestMultiHashMap.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[])
|
public static void main(String args[])
|
||||||
{
|
{
|
||||||
String[] testCaseName = { TestMultiHashMap.class.getName() };
|
String[] testCaseName = { TestMultiHashMap.class.getName() };
|
||||||
junit.textui.TestRunner.main(testCaseName);
|
junit.textui.TestRunner.main(testCaseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map makeEmptyMap() {
|
// MutltiHashMap was introduced in Collections 2.x
|
||||||
return new MultiHashMap();
|
public int getCompatibilityVersion() {
|
||||||
}
|
return 2;
|
||||||
|
}
|
||||||
//----------------------------
|
|
||||||
// Tests
|
public Map makeEmptyMap() {
|
||||||
//----------------------------
|
return new MultiHashMap();
|
||||||
public void testPutNGet()
|
}
|
||||||
{
|
|
||||||
MultiHashMap map = new MultiHashMap();
|
//----------------------------
|
||||||
loadMap( map );
|
// Tests
|
||||||
checkMap( map );
|
//----------------------------
|
||||||
|
public void testPutNGet()
|
||||||
assertTrue( map.get(new Integer(99)) == null );
|
{
|
||||||
|
MultiHashMap map = new MultiHashMap();
|
||||||
map.clear();
|
loadMap( map );
|
||||||
assertTrue( map.size() == 0 );
|
checkMap( map );
|
||||||
}
|
|
||||||
|
assertTrue( map.get(new Integer(99)) == null );
|
||||||
public void testContainsValue()
|
|
||||||
{
|
map.clear();
|
||||||
MultiHashMap map = new MultiHashMap();
|
assertTrue( map.size() == 0 );
|
||||||
loadMap( map );
|
}
|
||||||
|
|
||||||
assertTrue( map.containsValue( "uno" ) );
|
public void testContainsValue()
|
||||||
assertTrue( map.containsValue( "quatro" ) );
|
{
|
||||||
assertTrue( map.containsValue( "two" ) );
|
MultiHashMap map = new MultiHashMap();
|
||||||
|
loadMap( map );
|
||||||
assertTrue( ! map.containsValue( "uggaBugga" ) );
|
|
||||||
|
assertTrue( map.containsValue( "uno" ) );
|
||||||
map.clear();
|
assertTrue( map.containsValue( "quatro" ) );
|
||||||
}
|
assertTrue( map.containsValue( "two" ) );
|
||||||
|
|
||||||
public void testValues()
|
assertTrue( ! map.containsValue( "uggaBugga" ) );
|
||||||
{
|
|
||||||
MultiHashMap map = new MultiHashMap();
|
map.clear();
|
||||||
loadMap( map );
|
}
|
||||||
|
|
||||||
Collection vals = map.values();
|
public void testValues()
|
||||||
assertTrue( vals.size() == getFullSize() );
|
{
|
||||||
|
MultiHashMap map = new MultiHashMap();
|
||||||
map.clear();
|
loadMap( map );
|
||||||
}
|
|
||||||
|
Collection vals = map.values();
|
||||||
|
assertTrue( vals.size() == getFullSize() );
|
||||||
static private class MapPair
|
|
||||||
{
|
map.clear();
|
||||||
MapPair( int key, String val )
|
}
|
||||||
{
|
|
||||||
mKey = new Integer( key );
|
|
||||||
mValue = val;
|
static private class MapPair
|
||||||
}
|
{
|
||||||
|
MapPair( int key, String val )
|
||||||
Integer mKey = null;
|
{
|
||||||
String mValue = null;
|
mKey = new Integer( key );
|
||||||
}
|
mValue = val;
|
||||||
|
}
|
||||||
static private MapPair[][] sMapPairs =
|
|
||||||
{
|
Integer mKey = null;
|
||||||
{new MapPair(0,"zero")},
|
String mValue = null;
|
||||||
{new MapPair(1,"one"), new MapPair(1,"ONE"), new MapPair(1,"uno")},
|
}
|
||||||
{new MapPair(2,"two"), new MapPair(2,"two") },
|
|
||||||
{new MapPair(3,"three"), new MapPair(3,"THREE"), new MapPair(3,"tres")},
|
static private MapPair[][] sMapPairs =
|
||||||
{new MapPair(4,"four"), new MapPair(4,"quatro")}
|
{
|
||||||
};
|
{new MapPair(0,"zero")},
|
||||||
|
{new MapPair(1,"one"), new MapPair(1,"ONE"), new MapPair(1,"uno")},
|
||||||
private void loadMap( MultiHashMap map )
|
{new MapPair(2,"two"), new MapPair(2,"two") },
|
||||||
{
|
{new MapPair(3,"three"), new MapPair(3,"THREE"), new MapPair(3,"tres")},
|
||||||
// Set up so that we load the keys "randomly"
|
{new MapPair(4,"four"), new MapPair(4,"quatro")}
|
||||||
// (i.e. we don't want to load int row-order, so that all like keys
|
};
|
||||||
// load together. We want to mix it up...)
|
|
||||||
|
private void loadMap( MultiHashMap map )
|
||||||
int numRows = sMapPairs.length;
|
{
|
||||||
int maxCols = 0;
|
// Set up so that we load the keys "randomly"
|
||||||
for( int ii=0; ii < sMapPairs.length; ii++ ){
|
// (i.e. we don't want to load int row-order, so that all like keys
|
||||||
if ( sMapPairs[ii].length > maxCols )
|
// load together. We want to mix it up...)
|
||||||
maxCols = sMapPairs[ii].length;
|
|
||||||
}
|
int numRows = sMapPairs.length;
|
||||||
for( int ii=0; ii < maxCols; ii++ ){
|
int maxCols = 0;
|
||||||
for( int jj=0; jj < numRows; jj++ ){
|
for( int ii=0; ii < sMapPairs.length; ii++ ){
|
||||||
if ( ii < sMapPairs[jj].length ) {
|
if ( sMapPairs[ii].length > maxCols )
|
||||||
map.put( sMapPairs[jj][ii].mKey, sMapPairs[jj][ii].mValue);
|
maxCols = sMapPairs[ii].length;
|
||||||
//---------------------------------------------------------
|
}
|
||||||
}
|
for( int ii=0; ii < maxCols; ii++ ){
|
||||||
}
|
for( int jj=0; jj < numRows; jj++ ){
|
||||||
}
|
if ( ii < sMapPairs[jj].length ) {
|
||||||
assertTrue( map.size() == sMapPairs.length );
|
map.put( sMapPairs[jj][ii].mKey, sMapPairs[jj][ii].mValue);
|
||||||
}
|
//---------------------------------------------------------
|
||||||
|
}
|
||||||
private void checkMap( MultiHashMap map )
|
}
|
||||||
{
|
}
|
||||||
for( int ii=0; ii < sMapPairs.length; ii++ ){
|
assertTrue( map.size() == sMapPairs.length );
|
||||||
checkKeyList( map, ii );
|
}
|
||||||
}
|
|
||||||
}
|
private void checkMap( MultiHashMap map )
|
||||||
|
{
|
||||||
private void checkKeyList( MultiHashMap map, int index )
|
for( int ii=0; ii < sMapPairs.length; ii++ ){
|
||||||
{
|
checkKeyList( map, ii );
|
||||||
assertTrue( index < sMapPairs.length );
|
}
|
||||||
Integer key = sMapPairs[index][0].mKey ;
|
}
|
||||||
|
|
||||||
Object obj = map.get( key );
|
private void checkKeyList( MultiHashMap map, int index )
|
||||||
//--------------------------
|
{
|
||||||
|
assertTrue( index < sMapPairs.length );
|
||||||
assertTrue( obj != null );
|
Integer key = sMapPairs[index][0].mKey ;
|
||||||
assertTrue( obj instanceof Collection );
|
|
||||||
Collection keyList = (Collection)obj;
|
Object obj = map.get( key );
|
||||||
|
//--------------------------
|
||||||
assertTrue( keyList.size() == sMapPairs[index].length );
|
|
||||||
Iterator iter = keyList.iterator();
|
assertTrue( obj != null );
|
||||||
while ( iter.hasNext() ) {
|
assertTrue( obj instanceof Collection );
|
||||||
Object oval = iter.next();
|
Collection keyList = (Collection)obj;
|
||||||
assertTrue( oval != null );
|
|
||||||
assertTrue( oval instanceof String );
|
assertTrue( keyList.size() == sMapPairs[index].length );
|
||||||
String val = (String)oval;
|
Iterator iter = keyList.iterator();
|
||||||
boolean foundIt = false;
|
while ( iter.hasNext() ) {
|
||||||
for( int ii=0; ii < sMapPairs[index].length; ii++ ){
|
Object oval = iter.next();
|
||||||
if( val.equals( sMapPairs[index][ii].mValue ) )
|
assertTrue( oval != null );
|
||||||
foundIt = true;
|
assertTrue( oval instanceof String );
|
||||||
}
|
String val = (String)oval;
|
||||||
assertTrue( foundIt );
|
boolean foundIt = false;
|
||||||
}
|
for( int ii=0; ii < sMapPairs[index].length; ii++ ){
|
||||||
}
|
if( val.equals( sMapPairs[index][ii].mValue ) )
|
||||||
|
foundIt = true;
|
||||||
public int getFullSize()
|
}
|
||||||
{
|
assertTrue( foundIt );
|
||||||
int len = 0;
|
}
|
||||||
for( int ii=0; ii < sMapPairs.length; ii++ ){
|
}
|
||||||
len += sMapPairs[ii].length;
|
|
||||||
}
|
public int getFullSize()
|
||||||
return len;
|
{
|
||||||
}
|
int len = 0;
|
||||||
|
for( int ii=0; ii < sMapPairs.length; ii++ ){
|
||||||
|
len += sMapPairs[ii].length;
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testEntrySetIterator() {
|
public void testEntrySetIterator() {
|
||||||
}
|
}
|
||||||
|
@ -237,4 +242,4 @@ public class TestMultiHashMap extends TestMap
|
||||||
// for.
|
// for.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue