Search in sources :

Example 6 with LocationTrace

use of fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace in project NoCheatPlus by NoCheatPlus.

the class TestLocationTrace method testMaxAgeIterator.

@Test
public void testMaxAgeIterator() {
    int size = 80;
    LocationTrace trace = new LocationTrace(size, size, pool);
    // Adding up to size elements.
    for (int i = 0; i < size; i++) {
        trace.addEntry(i, i, i, i, 0, 0);
    }
    for (int i = 0; i < size; i++) {
        Iterator<ITraceEntry> it = trace.maxAgeIterator(i);
        long got = it.next().getTime();
        if (got != i) {
            fail("Bad entry point for iterator (maxAge), expected " + i + ", got instead: " + got);
        }
        int n = 1;
        while (it.hasNext()) {
            it.next();
            n++;
        }
        if (n != size - i) {
            fail("Bad number of elements for iterator (maxAge), expected " + (size - i) + ", got instead: " + n);
        }
    }
}
Also used : ITraceEntry(fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.ITraceEntry) LocationTrace(fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace) Test(org.junit.Test)

Example 7 with LocationTrace

use of fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace in project NoCheatPlus by NoCheatPlus.

the class TestLocationTrace method testMaxAgeFirstElementAnyway.

@Test
public void testMaxAgeFirstElementAnyway() {
    int size = 80;
    LocationTrace trace = new LocationTrace(size, size, pool);
    trace.addEntry(0, 0, 0, 0, 0, 0);
    if (!trace.maxAgeIterator(1000).hasNext()) {
        fail("Expect iterator (maxAge) to always contain the latest element.");
    }
    trace.addEntry(1, 0, 0, 0, 0, 0);
    final Iterator<ITraceEntry> it = trace.maxAgeIterator(2);
    if (!it.hasNext()) {
        fail("Expect iterator (maxAge) to always contain the latest element.");
    }
    it.next();
    if (it.hasNext()) {
        fail("Expect iterator (maxAge) to have only the latest element for all out of range entries.");
    }
}
Also used : ITraceEntry(fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.ITraceEntry) LocationTrace(fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace) Test(org.junit.Test)

Aggregations

LocationTrace (fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace)7 Test (org.junit.Test)6 ITraceEntry (fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.ITraceEntry)2 MovingConfig (fr.neatmonster.nocheatplus.checks.moving.MovingConfig)1 MovingData (fr.neatmonster.nocheatplus.checks.moving.MovingData)1 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)1 PlayerMoveInfo (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveInfo)1 Location (org.bukkit.Location)1 Player (org.bukkit.entity.Player)1