public void testAltIndexIsReversible() throws Exception { final long max = Long.MAX_VALUE - 1L; // must be even! final long incr = 1000000L; final Random random = new Random(1L); final byte[] fingerprint = new byte[1]; for (long index = 0; index != next(index, incr, max); index = next(index, incr, max)) { random.nextBytes(fingerprint); int f = (random.nextInt(126) + 1) * (random.nextBoolean() ? 1 : -1); final long altIndex = MURMUR128_BEALDUPRAS_32.altIndex(index, f, max); final long altAltIndex = MURMUR128_BEALDUPRAS_32.altIndex(altIndex, f, max); assertEquals("index should equal altIndex(altIndex(index)):" + f, index, altAltIndex); } }
public void testIndexIsModuloM() throws Exception { final int min = Integer.MIN_VALUE; final int max = Integer.MAX_VALUE; final int incr = 100000; final long m = 0x1DEAL; for (int hash = min; hash != next(hash, incr, max); hash = next(hash, incr, max)) { final long index = MURMUR128_BEALDUPRAS_32.index(hash, m); assertThat(index).isLessThan(m); assertThat(index).isGreaterThan(-1L); } }
public void testFingerprintBoundaries() throws Exception { assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0x80000000, 1)).isEqualTo(0x01); assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0xC0000000, 2)).isEqualTo(0x03); assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0xE0000000, 3)).isEqualTo(0x04); assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0xE0000000, 8)).isEqualTo(0xE0); assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0xE0000000, 16)).isEqualTo(0xE000); assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0x80000000, Integer.SIZE)).isEqualTo(0x80000000); for (int f = 1; f < Integer.SIZE; f++) { assertThat(MURMUR128_BEALDUPRAS_32.fingerprint(0x00, f)).isNotEqualTo(0x00); } }