CollisionDJBX31A implements CollisionInterface { @Override public int getHash( String s ) { byte[] byteArray = s.getBytes(); int n = byteArray.length; int hash = 0; for ( int i = 0; i < n; i++ ) { hash = ( ( hash << 5 ) - hash ) + byteArray[i]; } return hash; }  @Override int getHash( String s ); @Override void genNCollisions( int numberAttributes, StringBuilder sb, boolean useNamespace ); @Override String getCollisionString( int i, int n );  }
@Test public void testGetHash() { String s = "EzFY"; CollisionDJBX31A instance = new CollisionDJBX31A(); int expResult = 2175080; int result = instance.getHash( s ); assertEquals( expResult, result ); }
@Test public void testCollisionsFail() { CollisionDJBX31A instance = new CollisionDJBX31A(); int t1 = instance.getHash( "Ez" ); int t2 = instance.getHash( "Fy" ); int t3 = instance.getHash( "EzEz" ); int t4 = instance.getHash( "EzFY" ); int t5 = instance.getHash( "FYEz" ); int t6 = instance.getHash( "FYFY" ); if ( t1 != t2 && t2 != t3 && t3 != t4 && t4 != t5 && t5 != t6 ) { assertTrue( true ); } else { assertTrue( false ); } }
@Test public void testCollisionsOk() { CollisionDJBX31A instance = new CollisionDJBX31A(); int t1 = instance.getHash( "tttt" ); int t2 = instance.getHash( "ttuU" ); int t3 = instance.getHash( "ttv6" ); int t4 = instance.getHash( "uUtt" ); int t5 = instance.getHash( "uUuU" ); int t6 = instance.getHash( "uUv6" ); int t7 = instance.getHash( "v6tt" ); int t8 = instance.getHash( "v6uU" ); int t9 = instance.getHash( "v6v6" ); if ( t1 == t2 && t2 == t3 && t3 == t4 && t4 == t5 && t5 == t6 && t6 == t7 && t7 == t8 && t8 == t9 ) { assertTrue( true ); } else { assertTrue( false ); } }