use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherBuilderTest method buildResetTest.
/**
* Tests that build resets the builder.
*/
@Test
public void buildResetTest() {
builder.with(new byte[] { 123 });
final OfInt iter = builder.build().iterator(shape);
assertTrue(iter.hasNext());
iter.next();
assertFalse(iter.hasNext());
// Nothing added since last build so it should be an empty hasher
final OfInt iter2 = builder.build().iterator(shape);
assertFalse(iter2.hasNext());
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherBuilderTest method buildTest_Empty.
/**
* Tests that an empty hasher works as expected.
*/
@Test
public void buildTest_Empty() {
final DynamicHasher hasher = builder.build();
final OfInt iter = hasher.iterator(shape);
assertFalse(iter.hasNext());
assertThrows(NoSuchElementException.class, () -> iter.nextInt(), "Should have thrown NoSuchElementException");
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class DynamicHasherTest method testGetBits_MultipleHashes.
/**
* Tests that bits from multiple hashes are returned correctly.
*/
@Test
public void testGetBits_MultipleHashes() {
final int[] expected = { 6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62, 1, 63, 53, 43, 17, 7, 69, 59, 49, 39, 13, 3, 65, 55, 45, 35, 25 };
final Hasher hasher = builder.with("Hello", StandardCharsets.UTF_8).with("World", StandardCharsets.UTF_8).build();
final OfInt iter = hasher.iterator(shape);
for (final int element : expected) {
assertTrue(iter.hasNext());
assertEquals(element, iter.nextInt());
}
assertFalse(iter.hasNext());
assertThrows(NoSuchElementException.class, () -> iter.next(), "Should have thrown NoSuchElementException");
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class StaticHasherTest method assertSameBits.
/**
* Compare 2 static hashers to verify they have the same bits enabled.
*
* @param hasher1 the first static hasher.
* @param hasher2 the second static hasher.
*/
private void assertSameBits(final StaticHasher hasher1, final StaticHasher hasher2) {
final OfInt iter1 = hasher1.iterator(shape);
final OfInt iter2 = hasher2.iterator(shape);
while (iter1.hasNext()) {
assertTrue(iter2.hasNext(), "Not enough data in second hasher");
assertEquals(iter1.nextInt(), iter2.nextInt());
}
assertFalse(iter2.hasNext(), "Too much data in second hasher");
}
use of java.util.PrimitiveIterator.OfInt in project commons-collections by apache.
the class StaticHasherTest method testConstructor_Hasher.
/**
* Tests that passing a hasher other than a StaticHasher to the constructor works as
* expected.
*/
@Test
public void testConstructor_Hasher() {
final int[] expected = { 1, 3, 5, 7, 9 };
final Hasher testHasher = new Hasher() {
@Override
public OfInt iterator(final Shape shape) {
final int[] values = { 1, 3, 5, 7, 9, 3, 5, 1 };
return Arrays.stream(values).iterator();
}
@Override
public HashFunctionIdentity getHashFunctionIdentity() {
return testFunction;
}
};
final StaticHasher hasher = new StaticHasher(testHasher, shape);
final OfInt iter = hasher.iterator(shape);
for (final int element : expected) {
assertTrue(iter.hasNext());
assertEquals(element, iter.nextInt());
}
assertFalse(iter.hasNext());
}
Aggregations