use of fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.TraceIterator in project NoCheatPlus by NoCheatPlus.
the class TestLocationTrace method testIteratorSizeAndOrder.
private void testIteratorSizeAndOrder(LocationTrace trace, int expectedSize) {
int size = trace.size();
if (size != expectedSize) {
fail("LocationTrace size differs from expected. Expect " + expectedSize + ", got instead: " + size);
}
TraceIterator[] iterators = new TraceIterator[] { trace.oldestIterator(), trace.latestIterator(), // Asserts entries to start at time >= 0.
trace.maxAgeIterator(0) };
String[] iteratorNames = new String[] { "oldest", "latest", "maxAge" };
int[] increments = new int[] { 1, -1, 1 };
for (int i = 0; i < iterators.length; i++) {
int n = 0;
TraceIterator it = iterators[i];
ITraceEntry last = null;
ITraceEntry current = null;
while (it.hasNext()) {
current = it.next();
n++;
if (n > size) {
fail("Iterator (" + iteratorNames[i] + ") iterates too long.");
}
if (last != null) {
if (current.getTime() - last.getTime() != increments[i]) {
fail("Bad time increment (" + iteratorNames[i] + "). Expected " + increments[i] + ", got instead: " + (current.getTime() - last.getTime()));
}
}
last = current;
}
if (n != size) {
fail("Iterator (" + iteratorNames[i] + ") should have " + size + " elements, found instead: " + n);
}
}
}
Aggregations