Skip to content

Instantly share code, notes, and snippets.

@jy95
Created November 8, 2017 18:51
Show Gist options
  • Save jy95/ef5f5e09e6ab2639b23e40b39561cc46 to your computer and use it in GitHub Desktop.
Save jy95/ef5f5e09e6ab2639b23e40b39561cc46 to your computer and use it in GitHub Desktop.
TestHashCodes
public void TestHashCodes() {
MapInterface<Integer> map = new HashMap<Integer>();
// je génère des strings à la volée
for (int i = 0 ; i < 10 ; i++){
String txt = UUID.randomUUID().toString();
int hashcode = map.hashCode(txt);
// le hashcode doit être positif
assertTrue(hashcode >= 0);
// avec ce hashcode , on peut en déduire txt + char
char extendChar = 'B';
StringBuilder sb = new StringBuilder(txt);
sb.append(extendChar);
String newTxt = sb.toString();
int lastChar = txt.substring(txt.length() -1).charAt(0);
assertEquals(map.hashCode(newTxt), map.incrementalHashCode(newTxt,hashcode,lastChar));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment