-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
9933254
commit a7e8e76
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...engine/src/test/java/de/gurkenlabs/litiengine/entities/behavior/AStarPathFinderTests.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,87 @@ | ||
package de.gurkenlabs.litiengine.entities.behavior; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import de.gurkenlabs.litiengine.entities.IMobileEntity; | ||
import de.gurkenlabs.litiengine.environment.tilemap.IMap; | ||
import java.awt.Dimension; | ||
import java.awt.geom.Point2D; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class AStarPathFinderTests { | ||
private AStarPathFinder pathFinder; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
// Create a mock AStarGrid for testing | ||
AStarGrid grid = Mockito.mock(AStarGrid.class); | ||
Mockito.when(grid.getSize()).thenReturn(new Dimension(10, 10)); | ||
|
||
pathFinder = new AStarPathFinder(grid); | ||
} | ||
|
||
@Test | ||
void testConstructorWithAStarGrid() { | ||
assertNotNull(pathFinder); | ||
assertNotNull(pathFinder.getGrid()); | ||
} | ||
|
||
@Test | ||
void testConstructorWithSizeAndGridNodeSize() { | ||
AStarPathFinder pathFinder = new AStarPathFinder(new Dimension(10, 10), 32); | ||
assertNotNull(pathFinder); | ||
assertNotNull(pathFinder.getGrid()); | ||
} | ||
|
||
@Test | ||
void testConstructorWithIMapAndGridNodeSize() { | ||
IMap map = Mockito.mock(IMap.class); | ||
Mockito.when(map.getSizeInPixels()).thenReturn(new Dimension(640, 480)); | ||
Mockito.when(map.getTileSize()).thenReturn(new Dimension(32, 32)); | ||
|
||
AStarPathFinder pathFinder = new AStarPathFinder(map, 32); | ||
assertNotNull(pathFinder); | ||
assertNotNull(pathFinder.getGrid()); | ||
} | ||
|
||
@Test | ||
void testConstructorWithIMap() { | ||
IMap map = Mockito.mock(IMap.class); | ||
Mockito.when(map.getSizeInPixels()).thenReturn(new Dimension(640, 480)); | ||
Mockito.when(map.getTileSize()).thenReturn(new Dimension(32, 32)); | ||
|
||
AStarPathFinder pathFinder = new AStarPathFinder(map); | ||
assertNotNull(pathFinder); | ||
assertNotNull(pathFinder.getGrid()); | ||
} | ||
|
||
@Test | ||
void testFindPathWithDirectPath() { | ||
IMobileEntity entity = Mockito.mock(IMobileEntity.class); | ||
Mockito.when(entity.getCollisionBoxCenter()).thenReturn(new Point2D.Double(10, 10)); | ||
|
||
Path path = pathFinder.findPath(entity, new Point2D.Double(50, 50)); | ||
|
||
assertNotNull(path); | ||
assertFalse(path.getPoints().isEmpty()); | ||
assertEquals(new Point2D.Double(10, 10), path.getStart()); | ||
assertEquals(new Point2D.Double(50, 50), path.getTarget()); | ||
} | ||
|
||
@Test | ||
void testFindPathWithAStarPath() { | ||
IMobileEntity entity = Mockito.mock(IMobileEntity.class); | ||
Mockito.when(entity.getCollisionBoxCenter()).thenReturn(new Point2D.Double(10, 10)); | ||
|
||
Path path = pathFinder.findPath(entity, new Point2D.Double(90, 90)); | ||
|
||
assertNotNull(path); | ||
assertFalse(path.getPoints().isEmpty()); | ||
assertEquals(new Point2D.Double(10, 10), path.getStart()); | ||
assertEquals(new Point2D.Double(90, 90), path.getTarget()); | ||
} | ||
} |