Merge branch 'phase00' into main
This commit is contained in:
commit
2c9359c9cf
@ -4,7 +4,7 @@ name = MichaelChen
|
|||||||
|
|
||||||
solutionname = Solution_Phase$(phase)_$(name)
|
solutionname = Solution_Phase$(phase)_$(name)
|
||||||
target = $(solutionname)_V$(version).zip
|
target = $(solutionname)_V$(version).zip
|
||||||
package = $(solutionname).pdf
|
package = $(solutionname).pdf PlayerTest.java
|
||||||
latexmkflags =
|
latexmkflags =
|
||||||
|
|
||||||
.PHONY : all dev
|
.PHONY : all dev
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
package nl.tudelft.jpacman.level;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import nl.tudelft.jpacman.board.Board;
|
||||||
|
import nl.tudelft.jpacman.board.BoardFactory;
|
||||||
|
import nl.tudelft.jpacman.board.Direction;
|
||||||
|
import nl.tudelft.jpacman.board.Square;
|
||||||
|
import nl.tudelft.jpacman.game.Game;
|
||||||
|
import nl.tudelft.jpacman.game.GameFactory;
|
||||||
|
import nl.tudelft.jpacman.npc.ghost.GhostFactory;
|
||||||
|
import nl.tudelft.jpacman.sprite.PacManSprites;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test suite to confirm the correct behaviour of pellet consumtion as
|
||||||
|
* described in Scenario S2.1.
|
||||||
|
*
|
||||||
|
* @author Michael Chen
|
||||||
|
*/
|
||||||
|
class PlayerTest {
|
||||||
|
private MapParser parser;
|
||||||
|
private GameFactory gameFact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the game factory
|
||||||
|
*/
|
||||||
|
@BeforeEach
|
||||||
|
void setUpTest() {
|
||||||
|
PacManSprites sprites = new PacManSprites();
|
||||||
|
parser = new MapParser(new LevelFactory(sprites,
|
||||||
|
new GhostFactory(sprites)), new BoardFactory(sprites));
|
||||||
|
gameFact = new GameFactory(new PlayerFactory(sprites));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenario S2.1: The player consumes
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void playerConsumeTest() {
|
||||||
|
Level level = parser.parseMap(
|
||||||
|
Lists.newArrayList("####", "#P.#", "####"));
|
||||||
|
Board board = level.getBoard();
|
||||||
|
Game game = gameFact.createSinglePlayerGame(level);
|
||||||
|
Player player = game.getPlayers().get(0);
|
||||||
|
Square playerStart = board.squareAt(1, 1);
|
||||||
|
Square pelletPos = board.squareAt(2, 1);
|
||||||
|
|
||||||
|
// Given the game has started,
|
||||||
|
game.start();
|
||||||
|
assertThat(game.isInProgress()).isTrue();
|
||||||
|
assertThat(player.getScore()).isZero();
|
||||||
|
|
||||||
|
// and my Pacman is next to a square containing a pellet;
|
||||||
|
assertThat(pelletPos.getOccupants())
|
||||||
|
.hasAtLeastOneElementOfType(Pellet.class);
|
||||||
|
assertThat(pelletPos.getOccupants()).hasSize(1);
|
||||||
|
Pellet pellet = (Pellet) pelletPos.getOccupants().get(0);
|
||||||
|
assertThat(playerStart.getOccupants()).contains(player);
|
||||||
|
|
||||||
|
// When I press an arrow key towards that square;
|
||||||
|
game.move(player, Direction.EAST);
|
||||||
|
|
||||||
|
// Then my Pacman can move to that square,
|
||||||
|
assertThat(pelletPos.getOccupants()).contains(player);
|
||||||
|
|
||||||
|
// and I earn the points for the pellet,
|
||||||
|
assertThat(player.getScore()).isEqualTo(pellet.getValue());
|
||||||
|
|
||||||
|
// and the pellet disappears from that square.
|
||||||
|
assertThat(pelletPos.getOccupants()).doesNotContain(pellet);
|
||||||
|
|
||||||
|
game.stop();
|
||||||
|
}
|
||||||
|
}
|
@ -63,7 +63,7 @@
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
\def\name{[Add name here]}
|
\def\name{Michael Chen}
|
||||||
\def\group{\textit{Assigned in Phase 1}}
|
\def\group{\textit{Assigned in Phase 1}}
|
||||||
|
|
||||||
\begin{document}
|
\begin{document}
|
||||||
@ -75,7 +75,9 @@
|
|||||||
\begin{question}{Learn to Understand given JUnit Tests}%[0]
|
\begin{question}{Learn to Understand given JUnit Tests}%[0]
|
||||||
From the \texttt{src/test/java} folder, select 2 test files, and describe in your own words which parts of the system / program execution are tested, and which kind of failures may be targeted by these tests.
|
From the \texttt{src/test/java} folder, select 2 test files, and describe in your own words which parts of the system / program execution are tested, and which kind of failures may be targeted by these tests.
|
||||||
\begin{answer}
|
\begin{answer}
|
||||||
[TODO: Add answer here]
|
The \texttt{nl.tudelft.jpacman.npc.ghost.NavigationTest} class contains 8 test cases that test the capabilities of the \texttt{Navigation} class which is used to navigate the 2D maps and find paths to specific squares or types of objects. There are several test cases that verify the correct behaviour of the navigator: it checks if the navigator can find a correct path between to spaces, it verifies the correct failure return value in case no path can be found, it verifies that nearby objects of specific types can be found and also that certain navigator objects (ghosts, players, null) will navigate terrain differently (null can pass through wall squares). Each test consists of three steps: the preparation step parses a map from a list of lines in the grid and creates the squares that shall be navigated or objects to be found, the execution step then runs the navigation module with the test parameters, and finally the assertion step verifies the correctness of the execution results.
|
||||||
|
|
||||||
|
The \texttt{nl.tudelft.jpacman.board.OccupantTest} class contains a couple of tests that verify the correct behaviour of the occupancy protocol of the squares and units. The game rules define a strict 0..1 to 0..1 relation between those objects: each square can be occupied by at most one unit and each unit can occupy at most one square at a time. The tests here check if the relationship \textbf{on both sides} is successfully established once the unit tries to occupy a square that is accessible to the unit. It also checks that the square can be safely occupied multiple times.
|
||||||
\end{answer}
|
\end{answer}
|
||||||
\end{question}
|
\end{question}
|
||||||
|
|
||||||
@ -85,12 +87,9 @@
|
|||||||
\begin{question}{Write your own JUnit Test}%[0]
|
\begin{question}{Write your own JUnit Test}%[0]
|
||||||
Inside the \texttt{src/test/java} folder, create a new test file "CustomTest.java", and write your own JUnit test for one scenario picked from "scenarios.md" (located in the \texttt{doc/} folder). The test is supposed to call the sequence of functions corresponding to the steps described in the chosen scenario, and should include reasonable \textit{assertions} to check if the intermediate program states meet the scenario requirements.
|
Inside the \texttt{src/test/java} folder, create a new test file "CustomTest.java", and write your own JUnit test for one scenario picked from "scenarios.md" (located in the \texttt{doc/} folder). The test is supposed to call the sequence of functions corresponding to the steps described in the chosen scenario, and should include reasonable \textit{assertions} to check if the intermediate program states meet the scenario requirements.
|
||||||
\begin{answer}
|
\begin{answer}
|
||||||
[TODO: Add answer here]
|
I picked the scenarion \texttt{S2.1} to verify that the pellets are successfully consumed by the player once the player moves towards them.
|
||||||
|
|
||||||
\begin{lstlisting}[language=Java,belowskip=-0.8\baselineskip]
|
\lstinputlisting[firstline=43,lastline=78,language=Java,belowskip=-0.8\baselineskip]{PlayerTest.java}
|
||||||
/* Add code here */
|
|
||||||
\end{lstlisting}
|
|
||||||
% or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java}
|
|
||||||
\end{answer}
|
\end{answer}
|
||||||
\end{question}
|
\end{question}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user