-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7627067
commit cd76c3d
Showing
2 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
pathetic-engine/src/test/java/de/metaphoriker/pathetic/engine/result/PathImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package de.metaphoriker.pathetic.engine.result; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import de.metaphoriker.pathetic.api.pathing.result.Path; | ||
import de.metaphoriker.pathetic.api.wrapper.PathEnvironment; | ||
import de.metaphoriker.pathetic.api.wrapper.PathPosition; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class PathImplTest { | ||
|
||
@Test | ||
void testIterator() { | ||
List<PathPosition> positions = createPathPositions(5); | ||
Path path = new PathImpl(positions.get(0), positions.get(4), positions); | ||
|
||
int count = 0; | ||
for (PathPosition position : path) { | ||
assertEquals(positions.get(count), position); | ||
count++; | ||
} | ||
assertEquals(positions.size(), count); | ||
} | ||
|
||
@Test | ||
void testForEach() { | ||
List<PathPosition> positions = createPathPositions(5); | ||
Path path = new PathImpl(positions.get(0), positions.get(4), positions); | ||
|
||
List<PathPosition> collectedPositions = new ArrayList<>(); | ||
path.forEach(collectedPositions::add); | ||
|
||
assertEquals(positions, collectedPositions); | ||
} | ||
|
||
@Test | ||
void testInterpolate() { | ||
List<PathPosition> positions = createPathPositions(2); | ||
Path path = new PathImpl(positions.get(0), positions.get(1), positions); | ||
|
||
Path interpolatedPath = path.interpolate(0.5); | ||
|
||
assertEquals(6, interpolatedPath.length()); | ||
} | ||
|
||
@Test | ||
void testSimplify() { | ||
List<PathPosition> positions = createPathPositions(10); | ||
Path path = new PathImpl(positions.get(0), positions.get(9), positions); | ||
|
||
Path simplifiedPath = path.simplify(0.5); | ||
|
||
assertTrue(simplifiedPath.length() < path.length()); | ||
} | ||
|
||
@Test | ||
void testSimplifyInvalidEpsilon() { | ||
List<PathPosition> positions = createPathPositions(10); | ||
Path path = new PathImpl(positions.get(0), positions.get(9), positions); | ||
|
||
assertThrows(IllegalStateException.class, () -> path.simplify(-0.5)); | ||
assertThrows(IllegalStateException.class, () -> path.simplify(1.5)); | ||
} | ||
|
||
@Test | ||
void testJoin() { | ||
List<PathPosition> positions1 = createPathPositions(5); | ||
List<PathPosition> positions2 = createPathPositions(5, 5); | ||
Path path1 = new PathImpl(positions1.get(0), positions1.get(4), positions1); | ||
Path path2 = new PathImpl(positions2.get(0), positions2.get(4), positions2); | ||
|
||
Path joinedPath = path1.join(path2); | ||
|
||
assertEquals(positions1.get(0), joinedPath.getStart()); | ||
assertEquals(positions2.get(4), joinedPath.getEnd()); | ||
assertEquals(10, joinedPath.length()); | ||
} | ||
|
||
@Test | ||
void testTrim() { | ||
List<PathPosition> positions = createPathPositions(5); | ||
Path path = new PathImpl(positions.get(0), positions.get(4), positions); | ||
|
||
Path trimmedPath = path.trim(3); | ||
|
||
assertEquals(3, trimmedPath.length()); | ||
assertEquals(positions.get(0), trimmedPath.getStart()); | ||
assertEquals(positions.get(2), trimmedPath.getEnd()); | ||
} | ||
|
||
@Test | ||
void testMutatePositions() { | ||
List<PathPosition> positions = createPathPositions(5); | ||
Path path = new PathImpl(positions.get(0), positions.get(4), positions); | ||
|
||
Path mutatedPath = | ||
path.mutatePositions( | ||
position -> | ||
new PathPosition( | ||
Mockito.mock(PathEnvironment.class), | ||
position.getX() + 1, | ||
position.getY() + 1, | ||
position.getZ() + 1)); | ||
|
||
assertEquals(5, mutatedPath.length()); | ||
} | ||
|
||
@Test | ||
void testLength() { | ||
List<PathPosition> positions = createPathPositions(5); | ||
Path path = new PathImpl(positions.get(0), positions.get(4), positions); | ||
|
||
assertEquals(5, path.length()); | ||
} | ||
|
||
private List<PathPosition> createPathPositions(int numPositions) { | ||
return createPathPositions(numPositions, 0); | ||
} | ||
|
||
private List<PathPosition> createPathPositions(int numPositions, int startIndex) { | ||
List<PathPosition> positions = new ArrayList<>(); | ||
for (int i = startIndex; i < startIndex + numPositions; i++) { | ||
positions.add(new PathPosition(Mockito.mock(PathEnvironment.class), i, i, i)); | ||
} | ||
return positions; | ||
} | ||
} |