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

RandomUtil 2

parent 7c8699e5
Branches
No related tags found
No related merge requests found
package model;
import javafx.scene.paint.Color;
import java.util.List;
public class CyclicColorGenerator implements ColorGenerator {
public ArrayGrid grid;
List<Color> colors;
public CyclicColorGenerator(List<Color> colors) {
this.colors=colors;
}
@Override
public Color nextColor(Cell cell) {
return null;
}
}
......@@ -3,11 +3,11 @@ package model;
public class GrayGrid implements Grid{
private final int numberOfRows;
private final int numnberOfColumns;
private final int numberOfColumns;
public GrayGrid(int numberOfRows, int numberOfColumns){
this.numberOfRows = numberOfRows;
this.numnberOfColumns = numberOfColumns;
this.numberOfColumns = numberOfColumns;
}
/**
* Return the cell located at the given coordinates in the grid.
......@@ -38,11 +38,21 @@ public class GrayGrid implements Grid{
*/
@Override
public int getNumberOfColumns() {
return numnberOfColumns;
return numberOfColumns;
}
@Override
public void color(ColorGenerator colorGenerator) {
}
@Override
public boolean hasNext() {
return false;
}
@Override
public Cell next() {
return null;
}
}
package model;
import javafx.scene.paint.Color;
public class UniformExceptOneGenerator implements ColorGenerator {
public UniformExceptOneGenerator(Color uniformColor, Color exceptionColor) {
}
@Override
public Color nextColor(Cell cell) {
return null;
}
}
//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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment