Fixes #3344, Wrong iterator algorithm in PlotRangeIterator (#3345)

This commit is contained in:
Pascal Bürklin 2021-11-23 20:52:23 +01:00 committed by GitHub
parent a9f08bc885
commit 8f3fa419c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -302,7 +302,7 @@ public final class PlotId {
// first increase y, then x
if (this.y == this.end.getY()) {
this.x++;
this.y = 0;
this.y = this.start.getY();
} else {
this.y++;
}

View File

@ -25,7 +25,8 @@
*/
package com.plotsquared.core.plot;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
@ -33,6 +34,7 @@ import java.util.NoSuchElementException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
@ -106,4 +108,16 @@ public class PlotRangeIteratorTest {
assertThrows(NoSuchElementException.class, range::next);
}
@Test
public void resetYOfIteratorToStart() {
PlotId id00 = PlotId.of(0, 1);
PlotId id01 = PlotId.of(1, 2);
PlotId.PlotRangeIterator range = PlotId.PlotRangeIterator.range(id00, id01);
for (int i = 0; i < 4; i++) {
assertNotEquals(0, range.next().getY());
}
assertFalse(range.hasNext());
assertThrows(NoSuchElementException.class, range::next);
}
}