示例#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)));
 }
示例#2
0
  public void testCombineUnordered_randomHashCodes() {
    Random random = new Random();
    List<HashCode> hashCodes = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
      hashCodes.add(HashCodes.fromLong(random.nextLong()));
    }
    HashCode hashCode1 = Hashing.combineUnordered(hashCodes);
    Collections.shuffle(hashCodes);
    HashCode hashCode2 = Hashing.combineUnordered(hashCodes);

    assertEquals(hashCode1, hashCode2);
  }
示例#3
0
 public void testCombineUnordered_differentBitLengths() {
   try {
     Hashing.combineUnordered(ImmutableList.of(HashCodes.fromInt(32), HashCodes.fromLong(32L)));
     fail();
   } catch (IllegalArgumentException expected) {
   }
 }
示例#4
0
 public void testCombineUnordered_empty() {
   try {
     Hashing.combineUnordered(Collections.<HashCode>emptySet());
     fail();
   } catch (IllegalArgumentException expected) {
   }
 }
示例#5
0
 public void testCombineUnordered_null() {
   try {
     Hashing.combineUnordered(null);
     fail();
   } catch (NullPointerException expected) {
   }
 }
 private String generateHash(@Nonnull List<TableRow> rows) {
   List<HashCode> rowHashes = Lists.newArrayList();
   for (TableRow row : rows) {
     List<String> cellsInOneRow = Lists.newArrayList();
     for (TableCell cell : row.getF()) {
       cellsInOneRow.add(Objects.toString(cell.getV()));
       Collections.sort(cellsInOneRow);
     }
     rowHashes.add(Hashing.sha1().hashString(cellsInOneRow.toString(), StandardCharsets.UTF_8));
   }
   return Hashing.combineUnordered(rowHashes).toString();
 }