Example #1
0
 public void testCombineUnordered() {
   HashCode hash31 = HashCodes.fromInt(31);
   HashCode hash32 = HashCodes.fromInt(32);
   assertEquals(hash32, Hashing.combineUnordered(ImmutableList.of(hash32)));
   assertEquals(HashCodes.fromInt(64), Hashing.combineUnordered(ImmutableList.of(hash32, hash32)));
   assertEquals(
       HashCodes.fromInt(96), Hashing.combineUnordered(ImmutableList.of(hash32, hash32, hash32)));
   assertEquals(
       Hashing.combineUnordered(ImmutableList.of(hash31, hash32)),
       Hashing.combineUnordered(ImmutableList.of(hash32, hash31)));
 }
Example #2
0
 public void testCombineOrdered() {
   HashCode hash31 = HashCodes.fromInt(31);
   HashCode hash32 = HashCodes.fromInt(32);
   assertEquals(hash32, Hashing.combineOrdered(ImmutableList.of(hash32)));
   assertEquals(
       HashCodes.fromBytes(new byte[] {(byte) 0x80, 0, 0, 0}),
       Hashing.combineOrdered(ImmutableList.of(hash32, hash32)));
   assertEquals(
       HashCodes.fromBytes(new byte[] {(byte) 0xa0, 0, 0, 0}),
       Hashing.combineOrdered(ImmutableList.of(hash32, hash32, hash32)));
   assertFalse(
       Hashing.combineOrdered(ImmutableList.of(hash31, hash32))
           .equals(Hashing.combineOrdered(ImmutableList.of(hash32, hash31))));
 }
Example #3
0
 public void testCombineUnordered_differentBitLengths() {
   try {
     Hashing.combineUnordered(ImmutableList.of(HashCodes.fromInt(32), HashCodes.fromLong(32L)));
     fail();
   } catch (IllegalArgumentException expected) {
   }
 }
Example #4
0
 public void testConsistentHash_ofHashCode() {
   checkSameResult(HashCodes.fromLong(1), 1);
   checkSameResult(HashCodes.fromLong(0x9999999999999999L), 0x9999999999999999L);
   checkSameResult(HashCodes.fromInt(0x99999999), 0x0000000099999999L);
 }
Example #5
0
 public void testPadToLong() {
   assertEquals(0x1111111111111111L, Hashing.padToLong(HashCodes.fromLong(0x1111111111111111L)));
   assertEquals(0x9999999999999999L, Hashing.padToLong(HashCodes.fromLong(0x9999999999999999L)));
   assertEquals(0x0000000011111111L, Hashing.padToLong(HashCodes.fromInt(0x11111111)));
   assertEquals(0x0000000099999999L, Hashing.padToLong(HashCodes.fromInt(0x99999999)));
 }