Skip to content
Snippets Groups Projects
Commit 976240d4 authored by NGUYEN Thi hang's avatar NGUYEN Thi hang
Browse files

THN

parent 40981004
No related branches found
No related tags found
No related merge requests found
...@@ -7,36 +7,40 @@ import util.SetUtil; ...@@ -7,36 +7,40 @@ import util.SetUtil;
import java.util.*; import java.util.*;
public class ColoredCellIerator {/*implements Iterator<Cell> { public class ColoredCellIterator implements Iterator<Cell> {
Color color; private final Color color;
List<Cell> cells;
Set<Cell> visitedCells; Set<Cell> visitedCells;
Set<Cell> pendingCells=new HashSet<Cell>(); Set<Cell> pendingCells=new HashSet<Cell>();
public ColoredCellIerator(Cell startCell){ public ColoredCellIterator(Cell startCell){
this.color=startCell.getColor(); this.color=startCell.getColor();
this.visitedCells= new HashSet<Cell>(); this.visitedCells= new HashSet<Cell>();
this.pendingCells.add(startCell); pendingCells.add(startCell);
} }
@Override @Override
public boolean hasNext() { public boolean hasNext() {
if (this.pendingCells.size()==0) return false;
return true; return !pendingCells.isEmpty();
} }
@Override @Override
public Cell next() { public Cell next() {
for( int i=0; i< this.pendingCells.size();i++){
if (SetUtil.anyElement(this.pendingCells)!= SetUtil.anyElement(this.visitedCells)&&(SetUtil.anyElement(this.pendingCells).getColor()==this.color){ Cell pendingElement=SetUtil.anyElement(pendingCells);
//this.visitedCells.add(SetUtil.anyElement())
} for(Cell cell: pendingElement.getNeighbours()){
if( cell.getColor()==this.color&& !(visitedCells.contains(pendingElement)))
pendingCells.add(cell);
} }
visitedCells.add(pendingElement);
pendingCells.remove(pendingElement);
return pendingElement;
return null;
}*/ }
} }
...@@ -17,7 +17,7 @@ public class DistinctColorGenerator implements ColorGenerator { ...@@ -17,7 +17,7 @@ public class DistinctColorGenerator implements ColorGenerator {
List<Cell> neighbors = new ArrayList<>(); List<Cell> neighbors = new ArrayList<>();
System.out.println(neighbors.size()); //System.out.println(neighbors.size());
List<Color> neighbor_colors = new ArrayList<Color>(); List<Color> neighbor_colors = new ArrayList<Color>();
......
...@@ -19,7 +19,7 @@ class DistinctColorGeneratorTest { ...@@ -19,7 +19,7 @@ class DistinctColorGeneratorTest {
@Test @Test
void testNextColorWithTooFewAvailableColor() { void testNextColorWithTooFewAvailableColor() {
DistinctColorGenerator colorGeneratorOne = new DistinctColorGenerator(Color.RED, List.of(Color.RED)); DistinctColorGenerator colorGeneratorOne = new DistinctColorGenerator( List.of(Color.RED),Color.RED);
grid.color(colorGeneratorOne); grid.color(colorGeneratorOne);
assertThat(grid.getCell(0,0).getColor()).isEqualTo(Color.RED); assertThat(grid.getCell(0,0).getColor()).isEqualTo(Color.RED);
assertThat(grid.getCell(1,1).getColor()).isEqualTo(Color.RED); assertThat(grid.getCell(1,1).getColor()).isEqualTo(Color.RED);
...@@ -29,7 +29,7 @@ class DistinctColorGeneratorTest { ...@@ -29,7 +29,7 @@ class DistinctColorGeneratorTest {
@Test @Test
void testNextColorWithEnoughAvailableColor(){ void testNextColorWithEnoughAvailableColor(){
Color defaultColor = Color.BLACK; Color defaultColor = Color.BLACK;
DistinctColorGenerator colorGenerator = new DistinctColorGenerator(defaultColor, List.of(Color.RED,Color.BLUE,Color.YELLOW, Color.ORANGE)); DistinctColorGenerator colorGenerator = new DistinctColorGenerator( List.of(Color.RED,Color.BLUE,Color.YELLOW, Color.ORANGE),defaultColor);
grid.color(colorGenerator); grid.color(colorGenerator);
for(Cell cell: grid){ for(Cell cell: grid){
assertThat(cell.getNeighbours().stream().map(c-> c.getColor())).doesNotContain(cell.getColor()); assertThat(cell.getNeighbours().stream().map(c-> c.getColor())).doesNotContain(cell.getColor());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment