public void testHashCode() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap raw_map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
raw_map.put( keys[i], vals[i] );
}
Map<Integer,Long> map = TDecorators.wrap( raw_map );
TIntLongMap raw_other = new TIntLongHashMap();
Map<Integer,Long> other = TDecorators.wrap( raw_other );
other.putAll( map );
assertTrue( "hashcodes incorrectly not equal: " + map + ", " + other,
map.hashCode() == other.hashCode() );
TIntLongMap raw_unequal = new TIntLongHashMap();
for ( int key : keys ) {
raw_unequal.put( key, key );
}
Map<Integer,Long> unequal = TDecorators.wrap( raw_unequal );
assertFalse( "hashcodes unlikely equal: " + map + ", " + unequal,
map.hashCode() == unequal.hashCode() );
int[] raw_mismatched = {72, 49, 53, 1024, 999};
TIntLongMap raw_mismatched_map = new TIntLongHashMap();
for ( int aRaw_mismatched : raw_mismatched ) {
raw_mismatched_map.put( aRaw_mismatched, Long.valueOf( aRaw_mismatched * 37 ) );
}
Map<Integer,Long> mismatched = TDecorators.wrap( raw_mismatched_map );
assertFalse( "hashcodes unlikely equal: " + map + ", " + mismatched,
map.hashCode() == mismatched.hashCode() );
}