public void testKeySetRemoveAllTCollection() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
TIntSet set = map.keySet();
assertEquals( map.size(), set.size() );
assertFalse( set.isEmpty() );
assertTrue( set.removeAll( set ) );
assertTrue( set.isEmpty() );
// repopulate the set.
map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
set = map.keySet();
// With empty set
TIntSet tintset = new TIntHashSet();
assertFalse( "set: " + set + ", collection: " + tintset,
set.removeAll( tintset ) );
// With partial set
tintset = new TIntHashSet( keys );
tintset.remove( 42 );
assertTrue( "set: " + set + ", collection: " + tintset,
set.removeAll( tintset ) );
assertEquals( "set: " + set, 1, set.size() );
assertEquals( "set: " + set, 1, map.size() );
for ( int i = 0; i < keys.length; i++ ) {
if ( keys[i] == 42 ) {
assertTrue( set.contains( keys[i] ) );
assertTrue( map.containsKey( keys[i] ) );
} else {
assertFalse( set.contains( keys[i] ) );
assertFalse( map.containsKey( keys[i] ) );
}
}
// repopulate the set.
map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
set = map.keySet();
// Empty list
TIntCollection collection = new TIntArrayList();
assertFalse( "set: " + set + ", collection: " + collection,
set.removeAll( collection ) );
// partial list
collection = new TIntArrayList( keys );
collection.remove( 42 );
assertTrue( "set: " + set + ", collection: " + collection,
set.removeAll( collection ) );
assertEquals( "set: " + set, 1, set.size() );
assertEquals( "set: " + set, 1, map.size() );
for ( int i = 0; i < keys.length; i++ ) {
if ( keys[i] == 42 ) {
assertTrue( set.contains( keys[i] ) );
assertTrue( map.containsKey( keys[i] ) );
} else {
assertFalse( set.contains( keys[i] ) );
assertFalse( map.containsKey( keys[i] ) );
}
}
}