pathfinder test

This commit is contained in:
musilto9 2020-05-27 15:05:57 +02:00
parent 7c959b93c7
commit 292f446d10
8 changed files with 84 additions and 25 deletions

View File

@ -19,5 +19,18 @@
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0-M1" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0-M1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-module-junit4:2.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-module-junit4-common:2.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-reflect:2.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.9.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.9.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-core:2.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.javassist:javassist:3.27.0-GA" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-mockito2:2.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-support:2.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.28.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
</component> </component>
</module> </module>

13
pom.xml
View File

@ -25,5 +25,18 @@
<version>RELEASE</version> <version>RELEASE</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -33,6 +33,11 @@ public class Npc extends Person {
loadNpc(); loadNpc();
} }
public Npc(int x, int y, Map map, MapManager mapManager) {
super(x, y, map);
this.mapManager = mapManager;
}
public void move(int endX, int endY) { public void move(int endX, int endY) {
PathFinder pathFinder = new PathFinder(getMap()); PathFinder pathFinder = new PathFinder(getMap());
for (Direction direction: pathFinder.getWayWithCollision(getX(), getY(), endX, endY)){ for (Direction direction: pathFinder.getWayWithCollision(getX(), getY(), endX, endY)){
@ -97,15 +102,17 @@ public class Npc extends Person {
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
if (name != null) {
BufferedImage image = null; BufferedImage image = null;
try { try {
image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height); image = ImageIO.read(new File("src/main/resources/characters/" + imageNpc)).getSubimage(width * direction, 0, width, height);
g.drawImage(image, getX() * getSize() + (getSize() / 5) + offsetX, g.drawImage(image, getX() * getSize() + (getSize() / 5) + offsetX,
getY() * getSize() - (getSize() * 3/5) + offsetY, getSize() * widthCoef/5, getSize() * heightCoef/2, null); getY() * getSize() - (getSize() * 3 / 5) + offsetY, getSize() * widthCoef / 5, getSize() * heightCoef / 2, null);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
public void setDirection(int direction) { public void setDirection(int direction) {
this.direction = direction; this.direction = direction;

View File

@ -1,4 +0,0 @@
BLOCK 120
MOVETO 277
EVENT 334
TRIGGER 147

View File

@ -1,5 +1,9 @@
<tileset> A2_Ground.png 512 384 32 <tileset> A2_Ground.png 512 384 32
<tileset> D_OutDoor.png 512 512 32 <tileset> D_OutDoor.png 512 512 32
<cellmap> BLOCK 120
<cellmap> MOVETO 277
<cellmap> EVENT 334
<cellmap> TRIGGER 147
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

View File

@ -1,5 +1,5 @@
36 36 36 36
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK MOVETO,6,3,m1 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK SPAWN BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY
EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY BLOCK EMPTY BLOCK EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY

View File

@ -4,3 +4,4 @@
<0> boss <0> boss
<0> treasure <0> treasure
<1> glade <1> glade
<999> m6

View File

@ -1,8 +1,10 @@
package ruscz.game.gameOfProd.Scripts; package ruscz.game.gameOfProd.Scripts;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
import ruscz.game.gameOfProd.Cells.Npc;
import ruscz.game.gameOfProd.Map.Map; import ruscz.game.gameOfProd.Map.Map;
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
@ -13,34 +15,57 @@ public class PathFinderTest {
public static Stream<Arguments> argumentsStream(){ public static Stream<Arguments> argumentsStream(){
return Stream.of( return Stream.of(
Arguments.of(1,1,1,1) Arguments.of(1,1,8,8, true),
// Arguments.of(), Arguments.of(4, 7, 6, 1, true),
// Arguments.of(), Arguments.of(13, 1, 17, 9, true),
// Arguments.of(), Arguments.of(21, 1, 22, 9, true),
// Arguments.of() Arguments.of(26, 5, 33, 5, true),
Arguments.of(28, 3, 32, 7, true),
Arguments.of(29, 3, 29, 7, true),
Arguments.of(3, 17, 6, 17, true),
Arguments.of(3, 15, 5, 20, true),
Arguments.of(7, 17, 4, 18, true),
Arguments.of(13, 15, 22, 22, false),
Arguments.of(14, 20, 20, 16, false),
Arguments.of(26, 13, 30, 22, true),
Arguments.of(26, 13, 35, 20, true),
Arguments.of(1, 26, 9, 34, true),
Arguments.of(1, 26, 8, 26, true),
Arguments.of(22, 34, 17, 31, true),
Arguments.of(17, 31, 13, 34, true),
Arguments.of(27, 26, 33, 34, true),
Arguments.of(33, 34, 31, 32, true)
); );
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("argumentsStream") @MethodSource("argumentsStream")
public void getWayWithCollision_usingMap6ForTestOfPathFinding_rightPositionOfNpc(int startX, int startY, int endX, int endY) { public void getWayWithCollision_usingMap6ForTestOfPathFinding_rightPositionOfNpc(int startX, int startY, int endX, int endY, boolean isPossible) {
//Arrange //Arrange
WindowOfFreeMove freeMove; WindowOfFreeMove freeMove;
Map testMap;
Npc testNpc;
//Act //Act
freeMove = new WindowOfFreeMove(new JFrame()); freeMove = new WindowOfFreeMove(new JFrame());
freeMove.setVisible(false); freeMove.setVisible(false);
WindowOfFreeMove.setCHAPTER("999"); WindowOfFreeMove.setCHAPTER("999");
freeMove.start(true); freeMove.start(true);
freeMove.setMapManager(Map.findMapByName("m6",freeMove)); testMap = Map.findMapByName("m6",freeMove);
freeMove.setMapManager(testMap);
testNpc = new Npc(startX, startY, testMap, freeMove.getMapManager());
testNpc.move(endX, endY);
//Assert //Assert
if (isPossible) {
Assertions.assertEquals(endX, testNpc.getX());
Assertions.assertEquals(endY, testNpc.getY());
}
else {
Assertions.assertEquals(startX, testNpc.getX());
Assertions.assertEquals(startY, testNpc.getY());
}
} }