Skip to content
Snippets Groups Projects
Commit a7df92dd authored by MANSOUR Chadi's avatar MANSOUR Chadi
Browse files

Tests updated

parent 36d33e23
No related branches found
No related tags found
No related merge requests found
Pipeline #41330 passed
Showing
with 20 additions and 32 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -218,26 +218,6 @@ public class FirefighterBoard implements Board<List<ModelElement>> { ...@@ -218,26 +218,6 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
return modifiedPositions; return modifiedPositions;
} }
private Set<Position> spreadFire() {
Set<Position> newFirePositions = new HashSet<>();
for (Position firePosition : firePositions) {
newFirePositions.addAll(neighbors.get(firePosition)); // Spread fire to neighbors
}
return newFirePositions;
}
private void extinguishNearbyFire(List<Position> modifiedPositions) {
for (Position firefighterPosition : firefighterPositions) {
List<Position> nearbyFires = neighbors.get(firefighterPosition);
for (Position neighbor : nearbyFires) {
if (firePositions.contains(neighbor)) {
firePositions.remove(neighbor); // Extinguish fire in neighboring positions
modifiedPositions.add(neighbor);
}
}
}
}
public List<Pair<Position, ModelElement>> getUpdatedElements() { public List<Pair<Position, ModelElement>> getUpdatedElements() {
List<Pair<Position, ModelElement>> updatedElements = new ArrayList<>(); List<Pair<Position, ModelElement>> updatedElements = new ArrayList<>();
......
...@@ -75,4 +75,12 @@ public class FirefighterGrid extends Canvas { ...@@ -75,4 +75,12 @@ public class FirefighterGrid extends Canvas {
gc.strokeLine(0, row * boxHeight, getWidth(), row * boxHeight); // Horizontal lines gc.strokeLine(0, row * boxHeight, getWidth(), row * boxHeight); // Horizontal lines
} }
} }
public int getColumns() {
return columns;
}
public int getRows() {
return rows;
}
} }
...@@ -3,7 +3,7 @@ package view; ...@@ -3,7 +3,7 @@ package view;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
public enum ViewElement { public enum ViewElement {
ROAD(Color.GRAY), FIREFIGHTER(Color.BLUE), FIRE(Color.RED), EMPTY(Color.WHITE),CLAUD(Color.YELLOW); ROAD(Color.GRAY), FIREFIGHTER(Color.BLUE), FIRE(Color.RED), EMPTY(Color.WHITE),CLOUD(Color.YELLOW),MOUTAIN(Color.GREEN),ROCKS(Color.LIGHTSKYBLUE);
final Color color; final Color color;
......
...@@ -10,17 +10,17 @@ import static org.assertj.core.api.Assertions.*; ...@@ -10,17 +10,17 @@ import static org.assertj.core.api.Assertions.*;
public class FirefighterBoardTest { public class FirefighterBoardTest {
@Test @Test
void testColumnCount(){ void testColumnCount(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3); Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3,10,5,3,3);
assertThat(board.columnCount()).isEqualTo(20); assertThat(board.columnCount()).isEqualTo(20);
} }
@Test @Test
void testRowCount(){ void testRowCount(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3); Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3,10,5,3,3);
assertThat(board.rowCount()).isEqualTo(10); assertThat(board.rowCount()).isEqualTo(10);
} }
@Test @Test
void testStepNumber(){ void testStepNumber(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3); Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 1, 3,10,5,3,3);
for(int index = 0; index < 10; index++){ for(int index = 0; index < 10; index++){
assertThat(board.stepNumber()).isEqualTo(index); assertThat(board.stepNumber()).isEqualTo(index);
board.updateToNextGeneration(); board.updateToNextGeneration();
...@@ -29,7 +29,7 @@ public class FirefighterBoardTest { ...@@ -29,7 +29,7 @@ public class FirefighterBoardTest {
} }
@Test @Test
void testGetState_afterSet(){ void testGetState_afterSet(){
Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 0, 0); Board<List<ModelElement>> board = new FirefighterBoard(20, 10, 0, 0,0,0,0,0);
Position position = new Position(1,2); Position position = new Position(1,2);
assertThat(board.getState(position)).isEmpty(); assertThat(board.getState(position)).isEmpty();
board.setState(List.of(ModelElement.FIRE), position); board.setState(List.of(ModelElement.FIRE), position);
......
...@@ -7,14 +7,14 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -7,14 +7,14 @@ import static org.assertj.core.api.Assertions.assertThat;
public class FirefighterGridTest { public class FirefighterGridTest {
@Test @Test
void testColumnCount(){ void testColumnCount(){
Grid<ViewElement> grid = new FirefighterGrid(); FirefighterGrid grid = new FirefighterGrid();
grid.setDimensions(20,10,10,10); grid.initialize(20,10,10,10,null);
assertThat(grid.columnCount()).isEqualTo(20); assertThat(grid.getColumns()).isEqualTo(20);
} }
@Test @Test
void testRowCount(){ void testRowCount(){
Grid<ViewElement> grid = new FirefighterGrid(); FirefighterGrid grid = new FirefighterGrid();
grid.setDimensions(20,10,10,10); grid.initialize(20,10,10,10,null);
assertThat(grid.rowCount()).isEqualTo(10); assertThat(grid.getRows()).isEqualTo(10);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment