1 package gnu.trove; 19 20 import gnu.trove.decorator.TObjectIntHashMapDecorator; 21 import junit.framework.TestCase; 22 23 import java.util.*; 24 25 26 29 public class O2PHashMapTest extends TestCase { 30 31 public O2PHashMapTest( String name ) { 32 super( name ); 33 } 34 35 36 public void testKeys() { 37 TObjectIntHashMap<String > map = new TObjectIntHashMap<String >(); 38 39 map.put( "one", 1 ); 40 map.put( "two", 2 ); 41 42 assertEquals( 2, map.size() ); 43 44 String [] keys = map.keys( new String [ map.size() ] ); 45 assertEquals( 2, keys.length ); 46 List<String > keys_list = Arrays.asList( keys ); 47 48 assertTrue( keys_list.contains( "one" ) ); 49 assertTrue( keys_list.contains( "two" ) ); 50 51 Object [] keys2 = map.keys(); 52 assertEquals( 2, keys2.length ); 53 List keys_list2 = Arrays.asList( keys2 ); 54 55 assertTrue( keys_list2.contains( "one" ) ); 56 assertTrue( keys_list2.contains( "two" ) ); 57 } 58 59 60 public void testDecorator() { 61 TObjectIntHashMap<String > map = new TObjectIntHashMap<String >(); 62 63 map.put( "one", 1 ); 64 map.put( "two", 2 ); 65 66 Map<String ,Integer > decorator = new TObjectIntHashMapDecorator<String >( map ); 67 68 assertEquals( 2, decorator.size() ); 69 assertEquals( Integer.valueOf( 1 ), decorator.get( "one" ) ); 70 assertEquals( Integer.valueOf( 2 ), decorator.get( "two" ) ); 71 72 Set<String > decorator_keys = decorator.keySet(); 73 assertEquals( 2, decorator_keys.size() ); 74 Iterator<String > it = decorator_keys.iterator(); 75 int count = 0; 76 while( it.hasNext() ) { 77 count++; 78 System.out.println(it.next()); 79 } 80 assertEquals( 2, count ); 81 82 assertSame(map, ( ( TObjectIntHashMapDecorator ) decorator ).getMap() ); 83 } 84 85 86 public void testIterator() { 87 TObjectIntHashMap<String > map = new TObjectIntHashMap<String >(); 88 89 TObjectIntIterator<String > iterator = map.iterator(); 90 assertFalse( iterator.hasNext() ); 91 92 map.put( "one", 1 ); 93 map.put( "two", 2 ); 94 95 iterator = map.iterator(); 96 assertTrue( iterator.hasNext() ); 97 iterator.advance(); 98 assertTrue( iterator.hasNext() ); 99 iterator.advance(); 100 assertFalse( iterator.hasNext() ); 101 } 102 } 103 | Popular Tags |