I have this hashCode function that I have been trying to implement with Eclipse but my Tests keep failing. I am trying to write a Hashcode function that returns that last 2 or 3 chars of a word or number. Here is my current code:
public int hashCode(String value){
String test = value;
int hash = 1;
int len = test.length();
System.out.println(len);
for ( int i=0; i<len; i++ )
{
hash = 31 * hash + len;
}
return hash;
}
Here is my Junit Test:
@Test // hashCode()
public void testHashCode1() {
//Integer key1 = 123;
String key2 = "and";
assertEquals("and", key2.hashCode());
}
Everytime I run my test it fails indicating:
expected but was: <96727>
Now I really would like for this function to take in either a Word or Number and return the last two or three chars of the object taken in. Does anyone know how to do this using hashCode. Any help would be most appreciated