CS代写 package dungeonmania.mvp;

package dungeonmania.mvp;

import dungeonmania.DungeonManiaController;
import dungeonmania.response.models.DungeonResponse;

Copyright By PowCoder代写 加微信 powcoder

import dungeonmania.util.Direction;
import dungeonmania.exceptions.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

public class BuildablesTest {

@Tag(“5-1”)
@DisplayName(“Test IllegalArgumentException is raised when attempting to build an unknown entity – sword”)
public void buildSwordIllegalArgumentException() {
DungeonManiaController dmc;
dmc = new DungeonManiaController();
dmc.newGame(
“d_BuildablesTest_BuildSwordIllegalArgumentException”,
“c_BuildablesTest_BuildSwordIllegalArgumentException”);
assertThrows(IllegalArgumentException.class, () ->
dmc.build(“sword”)

@Tag(“5-2”)
@DisplayName(
“Test InvalidActionException is raised when the player does not have sufficient items to build a bow or shield”
public void buildInvalidActionException() {
DungeonManiaController dmc;
dmc = new DungeonManiaController();
dmc.newGame(“d_BuildablesTest_BuildInvalidArgumentException”, “c_BuildablesTest_BuildInvalidArgumentException”);
assertThrows(InvalidActionException.class, () ->
dmc.build(“bow”)

assertThrows(InvalidActionException.class, () ->
dmc.build(“shield”)

@Tag(“5-3”)
@DisplayName(“Test building a bow”)
public void buildBow() {
DungeonManiaController dmc;
dmc = new DungeonManiaController();
DungeonResponse res = dmc.newGame(“d_BuildablesTest_BuildBow”, “c_BuildablesTest_BuildBow”);

assertEquals(0, TestUtils.getInventory(res, “wood”).size());
assertEquals(0, TestUtils.getInventory(res, “arrow”).size());

// Pick up Wood
res = dmc.tick(Direction.RIGHT);
assertEquals(1, TestUtils.getInventory(res, “wood”).size());

// Pick up Arrow x3
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
assertEquals(3, TestUtils.getInventory(res, “arrow”).size());

// Build Bow
assertEquals(0, TestUtils.getInventory(res, “bow”).size());
res = assertDoesNotThrow(() -> dmc.build(“bow”));
assertEquals(1, TestUtils.getInventory(res, “bow”).size());

// Materials used in construction disappear from inventory
assertEquals(0, TestUtils.getInventory(res, “wood”).size());
assertEquals(0, TestUtils.getInventory(res, “arrow”).size());

@Tag(“5-4”)
@DisplayName(“Test building a shield with a key”)
public void buildShieldWithKey() {
DungeonManiaController dmc;
dmc = new DungeonManiaController();
DungeonResponse res = dmc.newGame(“d_BuildablesTest_BuildShieldWithKey”, “c_BuildablesTest_BuildShieldWithKey”);

assertEquals(0, TestUtils.getInventory(res, “wood”).size());
assertEquals(0, TestUtils.getInventory(res, “key”).size());

// Pick up Wood x2
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
assertEquals(2, TestUtils.getInventory(res, “wood”).size());

// Pick up Key
res = dmc.tick(Direction.RIGHT);
assertEquals(1, TestUtils.getInventory(res, “key”).size());

// Build Shield
assertEquals(0, TestUtils.getInventory(res, “shield”).size());
res = assertDoesNotThrow(() -> dmc.build(“shield”));
assertEquals(1, TestUtils.getInventory(res, “shield”).size());

// Materials used in construction disappear from inventory
assertEquals(0, TestUtils.getInventory(res, “wood”).size());
assertEquals(0, TestUtils.getInventory(res, “key”).size());

@Tag(“5-5”)
@DisplayName(“Test building a shield with treasure”)
public void buildShieldWithTreasure() {
DungeonManiaController dmc;
dmc = new DungeonManiaController();
DungeonResponse res = dmc.newGame(
“d_BuildablesTest_BuildShieldWithTreasure”, “c_BuildablesTest_BuildShieldWithTreasure”);
assertEquals(0, TestUtils.getInventory(res, “wood”).size());
assertEquals(0, TestUtils.getInventory(res, “treasure”).size());

// Pick up Wood x2
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
assertEquals(2, TestUtils.getInventory(res, “wood”).size());

// Pick up Treasure
res = dmc.tick(Direction.RIGHT);
assertEquals(1, TestUtils.getInventory(res, “treasure”).size());

// Build Shield
assertEquals(0, TestUtils.getInventory(res, “shield”).size());
res = assertDoesNotThrow(() -> dmc.build(“shield”));
assertEquals(1, TestUtils.getInventory(res, “shield”).size());

// Materials used in construction disappear from inventory
assertEquals(0, TestUtils.getInventory(res, “wood”).size());
assertEquals(0, TestUtils.getInventory(res, “treasure”).size());

@Tag(“5-6”)
@DisplayName(
“Test responsse buildables parameter is a list of buildables that the player can currently build”
public void dungeonResponseBuildables() {
DungeonManiaController dmc;
dmc = new DungeonManiaController();
DungeonResponse res = dmc.newGame(
“d_BuildablesTest_DungeonResponseBuildables”, “c_BuildablesTest_DungeonResponseBuildables”);

List buildables = new ArrayList<>();
assertEquals(buildables, res.getBuildables());

// Gather entities to build bow
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);

// Bow added to buildables list
buildables.add(“bow”);
assertEquals(buildables, res.getBuildables());

// Gather entities to build shield
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);
res = dmc.tick(Direction.RIGHT);

// Shield added to buildables list
buildables.add(“shield”);
assertEquals(buildables.size(), res.getBuildables().size());
assertTrue(buildables.containsAll(res.getBuildables()));
assertTrue(res.getBuildables().containsAll(buildables));

// Build bow
res = assertDoesNotThrow(() -> dmc.build(“bow”));
assertEquals(1, TestUtils.getInventory(res, “bow”).size());

// Bow disappears from buildables list
buildables.remove(“bow”);
assertEquals(buildables, res.getBuildables());

// Build shield
res = assertDoesNotThrow(() -> dmc.build(“shield”));
assertEquals(1, TestUtils.getInventory(res, “shield”).size());

// Shield disappears from buildables list
buildables.remove(“shield”);
assertEquals(buildables, res.getBuildables());

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com