public void testReallySimpleFingerprints() { assertEquals(8581389452482819506L, fingerprint("test".getBytes(UTF_8))); // 32 characters long assertEquals(-4196240717365766262L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); // 256 characters long assertEquals(3500507768004279527L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); }
public void testStringsConsistency() { for (String s : Arrays.asList("", "some", "test", "strings", "to", "try")) { assertEquals(HASH_FN.newHasher().putUnencodedChars(s).hash(), HASH_FN.hashUnencodedChars(s)); } }
public void testHashFloatIsStable() { // Just a spot check. Better than nothing. Hasher hasher = HASH_FN.newHasher(); hasher.putFloat(0x01000101f).putFloat(0f); assertEquals(0x49f9d18ee8ae1b28L, hasher.hash().asLong()); hasher = HASH_FN.newHasher(); hasher.putDouble(0x0000000001000101d); assertEquals(0x388ee898bad75cbfL, hasher.hash().asLong()); }
public void testUtf8() { char[] charsA = new char[128]; char[] charsB = new char[128]; for (int i = 0; i < charsA.length; i++) { if (i < 100) { charsA[i] = 'a'; charsB[i] = 'a'; } else { // Both two-byte characters, but must be different charsA[i] = (char) (0x0180 + i); charsB[i] = (char) (0x0280 + i); } } String stringA = new String(charsA); String stringB = new String(charsB); assertThat(stringA).isNotEqualTo(stringB); assertThat(HASH_FN.hashUnencodedChars(stringA)) .isNotEqualTo(HASH_FN.hashUnencodedChars(stringB)); assertThat(fingerprint(stringA.getBytes(UTF_8))) .isNotEqualTo(fingerprint(stringB.getBytes(UTF_8))); // ISO 8859-1 only has 0-255 (ubyte) representation so throws away UTF-8 characters // greater than 127 (ie with their top bit set). // Don't attempt to do this in real code. assertEquals( fingerprint(stringA.getBytes(ISO_8859_1)), fingerprint(stringB.getBytes(ISO_8859_1))); }
.putByte((byte) 0x00) .putByte((byte) 0x00); assertEquals(hashCode, hasher.hash().asLong()); .putChar((char) 0x0000) .putChar((char) 0x0000); assertEquals(hashCode, hasher.hash().asLong()); assertEquals(hashCode, hasher.hash().asLong()); assertEquals(hashCode, hasher.hash().asLong()); .putShort((short) 0x0000) .putShort((short) 0x0000); assertEquals(hashCode, hasher.hash().asLong());
buf[((x1 << 16) + (x2 << 8) + x3) % bufLen] ^= i % 256; assertEquals(0x7a1d67c50ec7e167L, h);
public void testReallySimpleFingerprints() { assertEquals(8581389452482819506L, fingerprint("test".getBytes(UTF_8))); // 32 characters long assertEquals(-4196240717365766262L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); // 256 characters long assertEquals(3500507768004279527L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); }
public void testStringsConsistency() { for (String s : Arrays.asList("", "some", "test", "strings", "to", "try")) { assertEquals(HASH_FN.newHasher().putUnencodedChars(s).hash(), HASH_FN.hashUnencodedChars(s)); } }
public void testHashFloatIsStable() { // Just a spot check. Better than nothing. Hasher hasher = HASH_FN.newHasher(); hasher.putFloat(0x01000101f).putFloat(0f); assertEquals(0x49f9d18ee8ae1b28L, hasher.hash().asLong()); hasher = HASH_FN.newHasher(); hasher.putDouble(0x0000000001000101d); assertEquals(0x388ee898bad75cbfL, hasher.hash().asLong()); }
public void testUtf8() { char[] charsA = new char[128]; char[] charsB = new char[128]; for (int i = 0; i < charsA.length; i++) { if (i < 100) { charsA[i] = 'a'; charsB[i] = 'a'; } else { // Both two-byte characters, but must be different charsA[i] = (char) (0x0180 + i); charsB[i] = (char) (0x0280 + i); } } String stringA = new String(charsA); String stringB = new String(charsB); assertThat(stringA).isNotEqualTo(stringB); assertThat(HASH_FN.hashUnencodedChars(stringA)) .isNotEqualTo(HASH_FN.hashUnencodedChars(stringB)); assertThat(fingerprint(stringA.getBytes(UTF_8))) .isNotEqualTo(fingerprint(stringB.getBytes(UTF_8))); // ISO 8859-1 only has 0-255 (ubyte) representation so throws away UTF-8 characters // greater than 127 (ie with their top bit set). // Don't attempt to do this in real code. assertEquals( fingerprint(stringA.getBytes(ISO_8859_1)), fingerprint(stringB.getBytes(ISO_8859_1))); }
.putByte((byte) 0x00) .putByte((byte) 0x00); assertEquals(hashCode, hasher.hash().asLong()); .putChar((char) 0x0000) .putChar((char) 0x0000); assertEquals(hashCode, hasher.hash().asLong()); assertEquals(hashCode, hasher.hash().asLong()); assertEquals(hashCode, hasher.hash().asLong()); .putShort((short) 0x0000) .putShort((short) 0x0000); assertEquals(hashCode, hasher.hash().asLong());
buf[((x1 << 16) + (x2 << 8) + x3) % bufLen] ^= i % 256; assertEquals(0x7a1d67c50ec7e167L, h);