Skip to content

Commit

Permalink
Fixes #3344, Wrong iterator algorithm in PlotRangeIterator (#3345)
Browse files Browse the repository at this point in the history
  • Loading branch information
buepas committed Nov 23, 2021
1 parent a9f08bc commit 8f3fa41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Core/src/main/java/com/plotsquared/core/plot/PlotId.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
*/
package com.plotsquared.core.plot;

import org.junit.Test;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 8f3fa41

Please sign in to comment.