From d8470790b2e39b84bb1a5eb189e0e4c014bb435b Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Fri, 15 Jul 2022 09:16:20 +0200 Subject: [PATCH 1/2] Finished Task 1 --- .../project_phase00_tasks/Solution_Phase00_MichaelChen.tex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex b/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex index fecebaa..c24e388 100644 --- a/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex +++ b/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex @@ -63,7 +63,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\def\name{[Add name here]} +\def\name{Michael Chen} \def\group{\textit{Assigned in Phase 1}} \begin{document} @@ -75,7 +75,9 @@ \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. \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{question} From f973e4db1110ebdf7f9285fc3210bbd72a09afbf Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Fri, 15 Jul 2022 12:01:37 +0200 Subject: [PATCH 2/2] Finished task 3 --- .../phase_00/project_phase00_tasks/Makefile | 2 +- .../project_phase00_tasks/PlayerTest.java | 79 +++++++++++++++++++ .../Solution_Phase00_MichaelChen.tex | 7 +- 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 project_task_sheets/phase_00/project_phase00_tasks/PlayerTest.java diff --git a/project_task_sheets/phase_00/project_phase00_tasks/Makefile b/project_task_sheets/phase_00/project_phase00_tasks/Makefile index ad9eaed..97ca527 100644 --- a/project_task_sheets/phase_00/project_phase00_tasks/Makefile +++ b/project_task_sheets/phase_00/project_phase00_tasks/Makefile @@ -4,7 +4,7 @@ name = MichaelChen solutionname = Solution_Phase$(phase)_$(name) target = $(solutionname)_V$(version).zip -package = $(solutionname).pdf +package = $(solutionname).pdf PlayerTest.java latexmkflags = .PHONY : all dev diff --git a/project_task_sheets/phase_00/project_phase00_tasks/PlayerTest.java b/project_task_sheets/phase_00/project_phase00_tasks/PlayerTest.java new file mode 100644 index 0000000..960eb2f --- /dev/null +++ b/project_task_sheets/phase_00/project_phase00_tasks/PlayerTest.java @@ -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(); + } +} diff --git a/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex b/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex index c24e388..afb6a25 100644 --- a/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex +++ b/project_task_sheets/phase_00/project_phase00_tasks/Solution_Phase00_MichaelChen.tex @@ -87,12 +87,9 @@ \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. \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] -/* Add code here */ - \end{lstlisting} - % or: \lstinputlisting[language=Java,belowskip=-0.8\baselineskip]{file_name.java} + \lstinputlisting[firstline=43,lastline=78,language=Java,belowskip=-0.8\baselineskip]{PlayerTest.java} \end{answer} \end{question}