private static void doTestIterators(Vector vector, Collection<Integer> expectedIndices) {
expectedIndices = Sets.newHashSet(expectedIndices);
Iterator<Element> allIterator = vector.all().iterator();
int index = 0;
while (allIterator.hasNext()) {
Element element = allIterator.next();
assertEquals(index, element.index());
if (expectedIndices.contains(index)) {
assertEquals((double) index * 2, element.get(), EPSILON);
} else {
assertEquals(0.0, element.get(), EPSILON);
}
index++;
}
for (Element element : vector.nonZeroes()) {
index = element.index();
assertTrue(expectedIndices.contains(index));
assertEquals((double) index * 2, element.get(), EPSILON);
expectedIndices.remove(index);
}
assertTrue(expectedIndices.isEmpty());
}