Created
November 8, 2017 18:51
-
-
Save jy95/ef5f5e09e6ab2639b23e40b39561cc46 to your computer and use it in GitHub Desktop.
TestHashCodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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