Skip to content
Snippets Groups Projects
Commit 25eb59fd authored by BEL KHALIFA Mohamed amine's avatar BEL KHALIFA Mohamed amine
Browse files

test valid

parent 0ca0963b
Branches
No related tags found
No related merge requests found
......@@ -40,4 +40,9 @@ public class GrayGrid implements Grid{
public int getNumberOfColumns() {
return numnberOfColumns;
}
@Override
public void color(ColorGenerator colorGenerator) {
}
}
......@@ -2,20 +2,21 @@ package model;
import javafx.scene.paint.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class SquareCell extends AbstractCell{
public List<Cell>neighbours;
private List<Cell>neighbours;
public SquareCell() {
Color DEFAULT_CELL_COLOR;
List<Cell> neighbours;
this.neighbours=new ArrayList<Cell>();
}
public SquareCell(Color color) {
this.setColor(color);
List<Cell> neighbours;
this.neighbours=new ArrayList<Cell>();
}
public SquareCell(Color color, List<Cell> neighbours) {
......
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Iterator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class ArrayGridTest {
private ArrayGrid arrayGridThreeFour;
private final ArrayGrid arrayGridTwoTwo = new ArrayGrid(2,2);
@BeforeEach
void initializeArrayGridThreeFour(){
arrayGridThreeFour = new ArrayGrid(3,4);
}
@Test
void testGetCellAndGridInitialization() {
assertThat(arrayGridThreeFour.getCell(0,0).getNeighbours())
.hasSize(2)
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,0), arrayGridThreeFour.getCell(0,1));
assertThat(arrayGridThreeFour.getCell(1,1).getNeighbours()).hasSize(4)
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(0,1),
arrayGridThreeFour.getCell(2,1),
arrayGridThreeFour.getCell(1,2),
arrayGridThreeFour.getCell(1,0));
assertThat(arrayGridThreeFour.getCell(2,3).getNeighbours()).hasSize(2)
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,3),
arrayGridThreeFour.getCell(2,2));
assertThat(arrayGridThreeFour.getCell(2,2).getNeighbours()).hasSize(3)
.containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,2),
arrayGridThreeFour.getCell(2,1),
arrayGridThreeFour.getCell(2,3));
}
@Test
void testConstructionWithIllegalParameters(){
assertThatThrownBy(() -> new ArrayGrid(-4,10)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> new ArrayGrid(4,0)).isInstanceOf(IllegalArgumentException.class);
}
@Test
void testGetNumberOfRows() {
assertThat(new ArrayGrid(100,200).getNumberOfRows()).isEqualTo(100);
}
@Test
void testGetNumberOfColumns() {
assertThat(new ArrayGrid(100,200).getNumberOfColumns()).isEqualTo(200);
}
private void setArrayGridThreeFourRed(){
for (int rowIndex = 0; rowIndex < 3; rowIndex++) {
for (int columnIndex = 0; columnIndex < 4; columnIndex++) {
arrayGridThreeFour.getCell(rowIndex,columnIndex).setColor(Color.RED);
}
}
}
@Test
void testColor() {
setArrayGridThreeFourRed();
arrayGridThreeFour.color(cell -> Color.BLACK);
for (int rowIndex = 0; rowIndex < 3; rowIndex++) {
for (int columnIndex = 0; columnIndex < 4; columnIndex++) {
assertThat(arrayGridThreeFour.getCell(rowIndex,columnIndex).getColor()).isEqualTo(Color.BLACK);
}
}
}
@Test
void testIterator() {
Iterator<Cell> iterator = arrayGridTwoTwo.iterator();
assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,0));
assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,1));
assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(1,0));
iterator.next();
assertThat(iterator.hasNext()).isFalse();
}
}
\ No newline at end of file
//package model;
//
//import javafx.scene.paint.Color;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//
//import java.util.Iterator;
//
//import static org.assertj.core.api.Assertions.assertThat;
//import static org.assertj.core.api.Assertions.assertThatThrownBy;
//
//class ArrayGridTest {
//
//
// private ArrayGrid arrayGridThreeFour;
// private final ArrayGrid arrayGridTwoTwo = new ArrayGrid(2,2);
//
// @BeforeEach
// void initializeArrayGridThreeFour(){
// arrayGridThreeFour = new ArrayGrid(3,4);
// }
//
//
// @Test
// void testGetCellAndGridInitialization() {
// assertThat(arrayGridThreeFour.getCell(0,0).getNeighbours())
// .hasSize(2)
// .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,0), arrayGridThreeFour.getCell(0,1));
// assertThat(arrayGridThreeFour.getCell(1,1).getNeighbours()).hasSize(4)
// .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(0,1),
// arrayGridThreeFour.getCell(2,1),
// arrayGridThreeFour.getCell(1,2),
// arrayGridThreeFour.getCell(1,0));
// assertThat(arrayGridThreeFour.getCell(2,3).getNeighbours()).hasSize(2)
// .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,3),
// arrayGridThreeFour.getCell(2,2));
// assertThat(arrayGridThreeFour.getCell(2,2).getNeighbours()).hasSize(3)
// .containsExactlyInAnyOrder(arrayGridThreeFour.getCell(1,2),
// arrayGridThreeFour.getCell(2,1),
// arrayGridThreeFour.getCell(2,3));
// }
//
// @Test
// void testConstructionWithIllegalParameters(){
// assertThatThrownBy(() -> new ArrayGrid(-4,10)).isInstanceOf(IllegalArgumentException.class);
// assertThatThrownBy(() -> new ArrayGrid(4,0)).isInstanceOf(IllegalArgumentException.class);
//
// }
// @Test
// void testGetNumberOfRows() {
// assertThat(new ArrayGrid(100,200).getNumberOfRows()).isEqualTo(100);
// }
//
// @Test
// void testGetNumberOfColumns() {
// assertThat(new ArrayGrid(100,200).getNumberOfColumns()).isEqualTo(200);
// }
//
// private void setArrayGridThreeFourRed(){
// for (int rowIndex = 0; rowIndex < 3; rowIndex++) {
// for (int columnIndex = 0; columnIndex < 4; columnIndex++) {
// arrayGridThreeFour.getCell(rowIndex,columnIndex).setColor(Color.RED);
// }
// }
// }
// @Test
// void testColor() {
// setArrayGridThreeFourRed();
// arrayGridThreeFour.color(cell -> Color.BLACK);
// for (int rowIndex = 0; rowIndex < 3; rowIndex++) {
// for (int columnIndex = 0; columnIndex < 4; columnIndex++) {
// assertThat(arrayGridThreeFour.getCell(rowIndex,columnIndex).getColor()).isEqualTo(Color.BLACK);
// }
// }
// }
//
// @Test
// void testIterator() {
// Iterator<Cell> iterator = arrayGridTwoTwo.iterator();
// assertThat(iterator.hasNext()).isTrue();
// assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,0));
// assertThat(iterator.hasNext()).isTrue();
// assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,1));
// assertThat(iterator.hasNext()).isTrue();
// assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(1,0));
// iterator.next();
// assertThat(iterator.hasNext()).isFalse();
//
// }
//}
\ No newline at end of file
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class ColoredCellIteratorTest {
/*
* +---+---+---+
* | R | B | R |
* +---+---+---|
* | R | R | B |
* |---+---+---+
* | B | B | R |
* +---+---+---+
*/
private static ArrayGrid gridThreeThree = new ArrayGrid(3,3);
@BeforeAll
private static void initializeColorsGrid(){
gridThreeThree.getCell(0,0).setColor(Color.RED);
gridThreeThree.getCell(0,1).setColor(Color.BLACK);
gridThreeThree.getCell(0,2).setColor(Color.RED);
gridThreeThree.getCell(1,0).setColor(Color.RED);
gridThreeThree.getCell(1,1).setColor(Color.RED);
gridThreeThree.getCell(1,2).setColor(Color.BLACK);
gridThreeThree.getCell(2,0).setColor(Color.BLACK);
gridThreeThree.getCell(2,1).setColor(Color.BLACK);
gridThreeThree.getCell(2,2).setColor(Color.RED);
}
@Test
void testIterator() {
ColoredCellIterator redCellIterator = new ColoredCellIterator(gridThreeThree.getCell(0,0));
List<Cell> expectedRedCells = List.of(gridThreeThree.getCell(0,0),
gridThreeThree.getCell(1,0),
gridThreeThree.getCell(1,1));
List<Cell> fromIteratorCells = new ArrayList<>();
for(;redCellIterator.hasNext();) fromIteratorCells.add(redCellIterator.next());
assertThat(fromIteratorCells).hasSameElementsAs(expectedRedCells).hasSameSizeAs(expectedRedCells);
ColoredCellIterator blackCellIterator = new ColoredCellIterator(gridThreeThree.getCell(2,1));
List<Cell> expectedBlackCells = List.of(gridThreeThree.getCell(2,0),
gridThreeThree.getCell(2,1));
fromIteratorCells = new ArrayList<>();
for( ; blackCellIterator.hasNext(); ) fromIteratorCells.add(blackCellIterator.next());
assertThat(fromIteratorCells).hasSameElementsAs(expectedBlackCells).hasSameSizeAs(expectedBlackCells);
}
}
\ No newline at end of file
//package model;
//
//import javafx.scene.paint.Color;
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.Test;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import static org.assertj.core.api.Assertions.assertThat;
//
//class ColoredCellIteratorTest {
//
//
// /*
// * +---+---+---+
// * | R | B | R |
// * +---+---+---|
// * | R | R | B |
// * |---+---+---+
// * | B | B | R |
// * +---+---+---+
// */
//
// private static ArrayGrid gridThreeThree = new ArrayGrid(3,3);
//
// @BeforeAll
// private static void initializeColorsGrid(){
// gridThreeThree.getCell(0,0).setColor(Color.RED);
// gridThreeThree.getCell(0,1).setColor(Color.BLACK);
// gridThreeThree.getCell(0,2).setColor(Color.RED);
// gridThreeThree.getCell(1,0).setColor(Color.RED);
// gridThreeThree.getCell(1,1).setColor(Color.RED);
// gridThreeThree.getCell(1,2).setColor(Color.BLACK);
// gridThreeThree.getCell(2,0).setColor(Color.BLACK);
// gridThreeThree.getCell(2,1).setColor(Color.BLACK);
// gridThreeThree.getCell(2,2).setColor(Color.RED);
// }
//
// @Test
// void testIterator() {
// ColoredCellIterator redCellIterator = new ColoredCellIterator(gridThreeThree.getCell(0,0));
// List<Cell> expectedRedCells = List.of(gridThreeThree.getCell(0,0),
// gridThreeThree.getCell(1,0),
// gridThreeThree.getCell(1,1));
// List<Cell> fromIteratorCells = new ArrayList<>();
// for(;redCellIterator.hasNext();) fromIteratorCells.add(redCellIterator.next());
// assertThat(fromIteratorCells).hasSameElementsAs(expectedRedCells).hasSameSizeAs(expectedRedCells);
//
// ColoredCellIterator blackCellIterator = new ColoredCellIterator(gridThreeThree.getCell(2,1));
// List<Cell> expectedBlackCells = List.of(gridThreeThree.getCell(2,0),
// gridThreeThree.getCell(2,1));
// fromIteratorCells = new ArrayList<>();
// for( ; blackCellIterator.hasNext(); ) fromIteratorCells.add(blackCellIterator.next());
// assertThat(fromIteratorCells).hasSameElementsAs(expectedBlackCells).hasSameSizeAs(expectedBlackCells);
//
// }
//
//}
\ No newline at end of file
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class ComputerPlayerTest {
@Test
void testSetStrategyAndPlay() {
ComputerPlayer player = new ComputerPlayer("computer",null);
player.setStrategy(startCell -> Color.INDIGO);
player.setStartCell(new SquareCell());
assertThat(player.play()).isEqualTo(Color.INDIGO);
}
@Test
void testIsHuman() {
assertThat(new ComputerPlayer("computer", null).isHuman()).isFalse();
}
}
\ No newline at end of file
//package model;
//
//import javafx.scene.paint.Color;
//import org.junit.jupiter.api.Test;
//
//import static org.assertj.core.api.Assertions.assertThat;
//
//class ComputerPlayerTest {
//
//
//
// @Test
// void testSetStrategyAndPlay() {
// ComputerPlayer player = new ComputerPlayer("computer",null);
// player.setStrategy(startCell -> Color.INDIGO);
// player.setStartCell(new SquareCell());
// assertThat(player.play()).isEqualTo(Color.INDIGO);
// }
//
//
// @Test
// void testIsHuman() {
// assertThat(new ComputerPlayer("computer", null).isHuman()).isFalse();
// }
//}
\ No newline at end of file
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class DistinctColorGeneratorTest {
private final static Color initialColor = Color.GRAY;
private final Grid grid = new ArrayGrid(2,3);
@BeforeEach
void initializeGridColor(){
for (Cell cell: grid)
cell.setColor(initialColor);
}
@Test
void testNextColorWithTooFewAvailableColor() {
DistinctColorGenerator colorGeneratorOne = new DistinctColorGenerator(Color.RED, List.of(Color.RED));
grid.color(colorGeneratorOne);
assertThat(grid.getCell(0,0).getColor()).isEqualTo(Color.RED);
assertThat(grid.getCell(1,1).getColor()).isEqualTo(Color.RED);
assertThat(grid.getCell(1,0).getColor()).isEqualTo(Color.RED);
}
@Test
void testNextColorWithEnoughAvailableColor(){
Color defaultColor = Color.BLACK;
DistinctColorGenerator colorGenerator = new DistinctColorGenerator(defaultColor, List.of(Color.RED,Color.BLUE,Color.YELLOW, Color.ORANGE));
grid.color(colorGenerator);
for(Cell cell: grid){
assertThat(cell.getNeighbours().stream().map(c-> c.getColor())).doesNotContain(cell.getColor());
assertThat(cell.getColor()).isNotEqualTo(defaultColor).isNotEqualTo(initialColor);
}
}
}
\ No newline at end of file
//package model;
//
//import javafx.scene.paint.Color;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//
//import java.util.List;
//
//import static org.assertj.core.api.Assertions.assertThat;
//
//class DistinctColorGeneratorTest {
// private final static Color initialColor = Color.GRAY;
// private final Grid grid = new ArrayGrid(2,3);
// @BeforeEach
// void initializeGridColor(){
// for (Cell cell: grid)
// cell.setColor(initialColor);
// }
//
// @Test
// void testNextColorWithTooFewAvailableColor() {
// DistinctColorGenerator colorGeneratorOne = new DistinctColorGenerator(Color.RED, List.of(Color.RED));
// grid.color(colorGeneratorOne);
// assertThat(grid.getCell(0,0).getColor()).isEqualTo(Color.RED);
// assertThat(grid.getCell(1,1).getColor()).isEqualTo(Color.RED);
// assertThat(grid.getCell(1,0).getColor()).isEqualTo(Color.RED);
// }
//
// @Test
// void testNextColorWithEnoughAvailableColor(){
// Color defaultColor = Color.BLACK;
// DistinctColorGenerator colorGenerator = new DistinctColorGenerator(defaultColor, List.of(Color.RED,Color.BLUE,Color.YELLOW, Color.ORANGE));
// grid.color(colorGenerator);
// for(Cell cell: grid){
// assertThat(cell.getNeighbours().stream().map(c-> c.getColor())).doesNotContain(cell.getColor());
// assertThat(cell.getColor()).isNotEqualTo(defaultColor).isNotEqualTo(initialColor);
// }
// }
//}
\ No newline at end of file
package model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static javafx.scene.paint.Color.*;
import static org.assertj.core.api.Assertions.assertThat;
class FloodGameTest {
private final int totalNumberOfCells = 6;
private final Grid gridTwoThree = new ArrayGrid(2,3);
private final Color colorONE = RED;
private final Color colorTWO = BLUE;
private FloodGame game;
private final Player playerONE = new ComputerPlayer("player1", gridTwoThree.getCell(0, 0), startCell -> colorONE);
private final Player playerTWO = new ComputerPlayer("player2", gridTwoThree.getCell(1, 2), startCell -> colorTWO);
@BeforeEach
private void initGame(){
game = new FloodGame(totalNumberOfCells);
}
@Test
void testSetTurnAndGetTurn() {
assertThat(game.getTurn()).isEqualTo(0);
game.setTurn(100);
assertThat(game.getTurn()).isEqualTo(100);
}
@Test
void testResetTurn() {
game.setTurn(100);
game.resetTurn();
assertThat(game.getTurn()).isEqualTo(0);
}
@Test
void testIncrementTurn() {
game.incrementTurn();
game.incrementTurn();
assertThat(game.getTurn()).isEqualTo(2);
}
@Test
void testGetPlayer() {
game.setPlayer(playerONE);
game.setPlayer(playerTWO);
assertThat(game.getPlayer()).isEqualTo(playerTWO);
game.incrementTurn();
assertThat(game.getPlayer()).isEqualTo(playerTWO);
}
@Test
void testIsHumanTurn() {
game.setPlayer(new HumanPlayer("human",gridTwoThree.getCell(1,2)));
assertThat(game.isHumanTurn()).isTrue();
game.setPlayer(playerONE);
assertThat(game.isHumanTurn()).isFalse();
}
private void fillGridYellow(Grid grid){
for(Cell cell: grid)
cell.setColor(YELLOW);
}
@Test
void testHasWon() {
game.setPlayer(playerONE);
gridTwoThree.getCell(0,0).setColor(RED);
gridTwoThree.getCell(1,1).setColor(BLUE);
assertThat(game.hasWon(game.getPlayer())).isFalse();
fillGridYellow(gridTwoThree);
assertThat(game.hasWon(game.getPlayer())).isTrue();
}
@Test
void testHasEnded() {
game.setPlayer(playerONE);
gridTwoThree.getCell(1,2).setColor(RED);
gridTwoThree.getCell(0,1).setColor(YELLOW);
assertThat(game.hasEnded()).isFalse();
fillGridYellow(gridTwoThree);
assertThat(game.hasEnded()).isTrue();
}
}
\ No newline at end of file
//package model;
//
//import javafx.scene.paint.Color;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//
//import static javafx.scene.paint.Color.*;
//import static org.assertj.core.api.Assertions.assertThat;
//
//class FloodGameTest {
//
// private final int totalNumberOfCells = 6;
// private final Grid gridTwoThree = new ArrayGrid(2,3);
// private final Color colorONE = RED;
// private final Color colorTWO = BLUE;
// private FloodGame game;
// private final Player playerONE = new ComputerPlayer("player1", gridTwoThree.getCell(0, 0), startCell -> colorONE);
// private final Player playerTWO = new ComputerPlayer("player2", gridTwoThree.getCell(1, 2), startCell -> colorTWO);
//
// @BeforeEach
// private void initGame(){
// game = new FloodGame(totalNumberOfCells);
// }
//
//
// @Test
// void testSetTurnAndGetTurn() {
// assertThat(game.getTurn()).isEqualTo(0);
// game.setTurn(100);
// assertThat(game.getTurn()).isEqualTo(100);
// }
//
//
//
//
// @Test
// void testResetTurn() {
// game.setTurn(100);
// game.resetTurn();
// assertThat(game.getTurn()).isEqualTo(0);
// }
//
//
// @Test
// void testIncrementTurn() {
// game.incrementTurn();
// game.incrementTurn();
// assertThat(game.getTurn()).isEqualTo(2);
// }
//
// @Test
// void testGetPlayer() {
// game.setPlayer(playerONE);
// game.setPlayer(playerTWO);
// assertThat(game.getPlayer()).isEqualTo(playerTWO);
// game.incrementTurn();
// assertThat(game.getPlayer()).isEqualTo(playerTWO);
// }
//
// @Test
// void testIsHumanTurn() {
// game.setPlayer(new HumanPlayer("human",gridTwoThree.getCell(1,2)));
// assertThat(game.isHumanTurn()).isTrue();
// game.setPlayer(playerONE);
// assertThat(game.isHumanTurn()).isFalse();
// }
//
// private void fillGridYellow(Grid grid){
// for(Cell cell: grid)
// cell.setColor(YELLOW);
// }
//
// @Test
// void testHasWon() {
// game.setPlayer(playerONE);
// gridTwoThree.getCell(0,0).setColor(RED);
// gridTwoThree.getCell(1,1).setColor(BLUE);
// assertThat(game.hasWon(game.getPlayer())).isFalse();
// fillGridYellow(gridTwoThree);
// assertThat(game.hasWon(game.getPlayer())).isTrue();
// }
//
// @Test
// void testHasEnded() {
// game.setPlayer(playerONE);
// gridTwoThree.getCell(1,2).setColor(RED);
// gridTwoThree.getCell(0,1).setColor(YELLOW);
// assertThat(game.hasEnded()).isFalse();
// fillGridYellow(gridTwoThree);
// assertThat(game.hasEnded()).isTrue();
// }
//
//}
\ No newline at end of file
......@@ -19,17 +19,17 @@ class SquareCellTest {
private final Cell centralCell = new SquareCell(Color.CHOCOLATE);
/* @BeforeEach
@BeforeEach
void testInitializeNeighbourhood(){
centralCell.setNeighbours(List.of(northCell,southCell,westCell,eastCell));
westCell.setNeighbours(List.of(centralCell));
eastCell.setNeighbours(List.of(centralCell));
southCell.setNeighbours(List.of(centralCell));
northCell.setNeighbours(List.of(centralCell));*/
}
@Test
void testIterator() {
northCell.setNeighbours(List.of(centralCell));
}
// @Test
// void testIterator() {
// }
@Test
void testGetNeighbours() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment