From 8f3fa419c4e8cf475d4398d6007d8022333ff389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20B=C3=BCrklin?= Date: Tue, 23 Nov 2021 20:52:23 +0100 Subject: [PATCH] Fixes #3344, Wrong iterator algorithm in PlotRangeIterator (#3345) --- .../java/com/plotsquared/core/plot/PlotId.java | 2 +- .../core/plot/PlotRangeIteratorTest.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotId.java b/Core/src/main/java/com/plotsquared/core/plot/PlotId.java index 9785f07e07..05c7f21b93 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotId.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotId.java @@ -302,7 +302,7 @@ public PlotId next() { // first increase y, then x if (this.y == this.end.getY()) { this.x++; - this.y = 0; + this.y = this.start.getY(); } else { this.y++; } diff --git a/Core/src/test/java/com/plotsquared/core/plot/PlotRangeIteratorTest.java b/Core/src/test/java/com/plotsquared/core/plot/PlotRangeIteratorTest.java index 7cc86619fe..605e22d7a1 100644 --- a/Core/src/test/java/com/plotsquared/core/plot/PlotRangeIteratorTest.java +++ b/Core/src/test/java/com/plotsquared/core/plot/PlotRangeIteratorTest.java @@ -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 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 void rectangleXAreaPlotIterator() { 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); + } }