La til test for å sjekke at getPositionsOfWallOnBoard har rett type og antall med flere argumenter

La til hjelpefunksjoner for å sjekke at alle elementer er av rett type
This commit is contained in:
GabrielMagnus 2020-03-17 14:02:04 +01:00
parent c846adcb14
commit 875363708c

View File

@ -221,10 +221,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfTileOnBoardHasTypeCogwheelLeft() { public void getPositionsOfTileOnBoardHasTypeCogwheelLeft() {
List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
assertTrue(checkIfAllElementsAreOfSpecificTileType(boardElemList, TileType.COGWHEEL_LEFT));
for (BoardElementContainer<Tile> elem : boardElemList) {
assertEquals(elem.getElement().getTileType(), TileType.COGWHEEL_LEFT);
}
} }
@Test @Test
@ -236,10 +233,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfTileOnBoardHasTypeTile() { public void getPositionsOfTileOnBoardHasTypeTile() {
List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE); List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE);
assertTrue(checkIfAllElementsAreOfSpecificTileType(boardElemList, TileType.TILE));
for (BoardElementContainer<Tile> elem : boardElemList) {
assertEquals(elem.getElement().getTileType(), TileType.TILE);
}
} }
@Test @Test
@ -251,10 +245,7 @@ public class BoardTest {
@Test @Test
public void getPositionsOfWallOnBoardHasTypeWallNormal() { public void getPositionsOfWallOnBoardHasTypeWallNormal() {
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL); List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL);
assertTrue(checkIfAllElementsAreOfSpecificWallType(boardElemList, WallType.WALL_NORMAL));
for (BoardElementContainer<Wall> elem : boardElemList) {
assertEquals(elem.getElement().getWallType(), WallType.WALL_NORMAL);
}
} }
@Test @Test
@ -266,17 +257,32 @@ public class BoardTest {
@Test @Test
public void getPositionsOfWallOnBoardHasTypeWallCorner() { public void getPositionsOfWallOnBoardHasTypeWallCorner() {
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
assertTrue(checkIfAllElementsAreOfSpecificWallType(boardElemList, WallType.WALL_CORNER));
for (BoardElementContainer<Wall> elem : boardElemList) {
assertEquals(elem.getElement().getWallType(), WallType.WALL_CORNER);
}
} }
@Test @Test
public void getPositionsOfWallOnBoardHasCorrect() { public void getPositionsOfWallOnBoardHasCorrectTypesWithMultipleParameters() {
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); List<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT, TileType.COGWHEEL_RIGHT);
Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getElement().getWallType() == WallType.WALL_CORNER; List<TileType> tileTypeList = new ArrayList<>();
boardElemList.removeIf(pred); List<TileType> tileTypeListResult = new ArrayList<>();
assertEquals(0, boardElemList.size()); tileTypeList.add(TileType.COGWHEEL_LEFT);
tileTypeList.add(TileType.COGWHEEL_RIGHT);
for (BoardElementContainer<Tile> elem : boardElemList) {
tileTypeListResult.add(elem.getElement().getTileType());
}
assertTrue(tileTypeList.containsAll(tileTypeListResult) && tileTypeListResult.containsAll(tileTypeList));
}
public <K> boolean checkIfAllElementsAreOfSpecificWallType(List<BoardElementContainer<Wall>> elemList, K WallType) {
Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getElement().getWallType() == WallType;
elemList.removeIf(pred);
return 0 == elemList.size();
}
public <K> boolean checkIfAllElementsAreOfSpecificTileType(List<BoardElementContainer<Tile>> elemList, K TileType) {
Predicate<BoardElementContainer<Tile>> pred = (element) -> element.getElement().getTileType() == TileType;
elemList.removeIf(pred);
return 0 == elemList.size();
} }
} }