CollisionDJBX33A implements CollisionInterface { @Override public int getHash( String s ) { byte[] byteArray = s.getBytes(); int n = byteArray.length; int hash = 5381; 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 = "AzC8"; CollisionDJBX33A instance = new CollisionDJBX33A(); int expResult = 2088944635; int result = instance.getHash( s ); assertEquals( expResult, result ); }
@Test public void testCollisionsFail() { CollisionDJBX33A instance = new CollisionDJBX33A(); int t1 = instance.getHash( "AB" ); int t2 = instance.getHash( "Cd" ); int t3 = instance.getHash( "ABAB" ); int t4 = instance.getHash( "ABCd" ); int t5 = instance.getHash( "CdAB" ); int t6 = instance.getHash( "CdCd" ); if ( t1 != t2 && t2 != t3 && t3 != t4 && t4 != t5 && t5 != t6 ) { assertTrue( true ); } else { assertTrue( false ); } }
@Test public void testCollisionsOk() { CollisionDJBX33A instance = new CollisionDJBX33A(); int t1 = instance.getHash( "Az" ); int t2 = instance.getHash( "C8" ); int t3 = instance.getHash( "AzAz" ); int t4 = instance.getHash( "AzC8" ); int t5 = instance.getHash( "C8Az" ); int t6 = instance.getHash( "C8C8" ); if ( t1 == t2 && t3 == t4 && t4 == t5 && t5 == t6 ) { assertTrue( true ); } else { assertTrue( false ); } }