From 875363708cf7369db071b0d6a7cc2af808bf1d4f Mon Sep 17 00:00:00 2001 From: GabrielMagnus Date: Tue, 17 Mar 2020 14:02:04 +0100 Subject: [PATCH] =?UTF-8?q?La=20til=20test=20for=20=C3=A5=20sjekke=20at=20?= =?UTF-8?q?getPositionsOfWallOnBoard=20har=20rett=20type=20og=20antall=20m?= =?UTF-8?q?ed=20flere=20argumenter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La til hjelpefunksjoner for å sjekke at alle elementer er av rett type --- .../fiasko/roborally/objects/BoardTest.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index 7f10db1..ac9eb72 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -221,10 +221,7 @@ public class BoardTest { @Test public void getPositionsOfTileOnBoardHasTypeCogwheelLeft() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getTileType(), TileType.COGWHEEL_LEFT); - } + assertTrue(checkIfAllElementsAreOfSpecificTileType(boardElemList, TileType.COGWHEEL_LEFT)); } @Test @@ -236,10 +233,7 @@ public class BoardTest { @Test public void getPositionsOfTileOnBoardHasTypeTile() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getTileType(), TileType.TILE); - } + assertTrue(checkIfAllElementsAreOfSpecificTileType(boardElemList, TileType.TILE)); } @Test @@ -251,10 +245,7 @@ public class BoardTest { @Test public void getPositionsOfWallOnBoardHasTypeWallNormal() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getWallType(), WallType.WALL_NORMAL); - } + assertTrue(checkIfAllElementsAreOfSpecificWallType(boardElemList, WallType.WALL_NORMAL)); } @Test @@ -266,17 +257,32 @@ public class BoardTest { @Test public void getPositionsOfWallOnBoardHasTypeWallCorner() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getWallType(), WallType.WALL_CORNER); - } + assertTrue(checkIfAllElementsAreOfSpecificWallType(boardElemList, WallType.WALL_CORNER)); } @Test - public void getPositionsOfWallOnBoardHasCorrect() { - List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); - Predicate> pred = (element) -> element.getElement().getWallType() == WallType.WALL_CORNER; - boardElemList.removeIf(pred); - assertEquals(0, boardElemList.size()); + public void getPositionsOfWallOnBoardHasCorrectTypesWithMultipleParameters() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT, TileType.COGWHEEL_RIGHT); + List tileTypeList = new ArrayList<>(); + List tileTypeListResult = new ArrayList<>(); + tileTypeList.add(TileType.COGWHEEL_LEFT); + tileTypeList.add(TileType.COGWHEEL_RIGHT); + + for (BoardElementContainer elem : boardElemList) { + tileTypeListResult.add(elem.getElement().getTileType()); + } + + assertTrue(tileTypeList.containsAll(tileTypeListResult) && tileTypeListResult.containsAll(tileTypeList)); + } + + public boolean checkIfAllElementsAreOfSpecificWallType(List> elemList, K WallType) { + Predicate> pred = (element) -> element.getElement().getWallType() == WallType; + elemList.removeIf(pred); + return 0 == elemList.size(); + } + public boolean checkIfAllElementsAreOfSpecificTileType(List> elemList, K TileType) { + Predicate> pred = (element) -> element.getElement().getTileType() == TileType; + elemList.removeIf(pred); + return 0 == elemList.size(); } }