Skip to content
Snippets Groups Projects
Commit aa69c8eb authored by EL GAOUAL Zaid's avatar EL GAOUAL Zaid
Browse files

Merge remote-tracking branch 'origin/main'

parents fe63ef3b 44f9dcba
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ public class ArrayGrid implements Grid{ ...@@ -45,7 +45,7 @@ public class ArrayGrid implements Grid{
} }
public Iterator<Cell> iterator() { public Iterator<Cell> iterator() {
return null; return new CellGridIterator(this);
} }
@Override @Override
......
...@@ -4,7 +4,7 @@ import java.util.List; ...@@ -4,7 +4,7 @@ import java.util.List;
public class CyclicColorGenerator implements ColorGenerator { public class CyclicColorGenerator implements ColorGenerator {
public ArrayGrid grid; public ArrayGrid grid;
List<Color> colors; public List<Color> colors;
public CyclicColorGenerator(List<Color> colors) { public CyclicColorGenerator(List<Color> colors) {
this.colors=colors; this.colors=colors;
......
...@@ -74,17 +74,17 @@ class ArrayGridTest { ...@@ -74,17 +74,17 @@ class ArrayGridTest {
} }
} }
// @Test @Test
// void testIterator() { void testIterator() {
// Iterator<Cell> iterator = arrayGridTwoTwo.iterator(); Iterator<Cell> iterator = arrayGridTwoTwo.iterator();
// assertThat(iterator.hasNext()).isTrue(); assertThat(iterator.hasNext()).isTrue();
// assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,0)); assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,0));
// assertThat(iterator.hasNext()).isTrue(); assertThat(iterator.hasNext()).isTrue();
// assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,1)); assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(0,1));
// assertThat(iterator.hasNext()).isTrue(); assertThat(iterator.hasNext()).isTrue();
// assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(1,0)); assertThat(iterator.next()).isEqualTo(arrayGridTwoTwo.getCell(1,0));
// iterator.next(); iterator.next();
// assertThat(iterator.hasNext()).isFalse(); assertThat(iterator.hasNext()).isFalse();
//
// } }
} }
\ No newline at end of file
package model; //package model;
//
import javafx.scene.paint.Color; //import javafx.scene.paint.Color;
import org.junit.jupiter.api.BeforeAll; //import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
import static org.assertj.core.api.Assertions.assertThat; //import static org.assertj.core.api.Assertions.assertThat;
//
class ColoredCellIteratorTest { //class ColoredCellIteratorTest {
//
//
/* // /*
* +---+---+---+ // * +---+---+---+
* | R | B | R | // * | R | B | R |
* +---+---+---| // * +---+---+---|
* | R | R | B | // * | R | R | B |
* |---+---+---+ // * |---+---+---+
* | B | B | R | // * | B | B | R |
* +---+---+---+ // * +---+---+---+
*/ // */
//
private static ArrayGrid gridThreeThree = new ArrayGrid(3,3); // private static ArrayGrid gridThreeThree = new ArrayGrid(3,3);
//
@BeforeAll // @BeforeAll
private static void initializeColorsGrid(){ // private static void initializeColorsGrid(){
gridThreeThree.getCell(0,0).setColor(Color.RED); // gridThreeThree.getCell(0,0).setColor(Color.RED);
gridThreeThree.getCell(0,1).setColor(Color.BLACK); // gridThreeThree.getCell(0,1).setColor(Color.BLACK);
gridThreeThree.getCell(0,2).setColor(Color.RED); // gridThreeThree.getCell(0,2).setColor(Color.RED);
gridThreeThree.getCell(1,0).setColor(Color.RED); // gridThreeThree.getCell(1,0).setColor(Color.RED);
gridThreeThree.getCell(1,1).setColor(Color.RED); // gridThreeThree.getCell(1,1).setColor(Color.RED);
gridThreeThree.getCell(1,2).setColor(Color.BLACK); // gridThreeThree.getCell(1,2).setColor(Color.BLACK);
gridThreeThree.getCell(2,0).setColor(Color.BLACK); // gridThreeThree.getCell(2,0).setColor(Color.BLACK);
gridThreeThree.getCell(2,1).setColor(Color.BLACK); // gridThreeThree.getCell(2,1).setColor(Color.BLACK);
gridThreeThree.getCell(2,2).setColor(Color.RED); // gridThreeThree.getCell(2,2).setColor(Color.RED);
} // }
//
@Test // @Test
void testIterator() { // void testIterator() {
ColoredCellIterator redCellIterator = new ColoredCellIterator(gridThreeThree.getCell(0,0)); // ColoredCellIterator redCellIterator = new ColoredCellIterator(gridThreeThree.getCell(0,0));
List<Cell> expectedRedCells = List.of(gridThreeThree.getCell(0,0), // List<Cell> expectedRedCells = List.of(gridThreeThree.getCell(0,0),
gridThreeThree.getCell(1,0), // gridThreeThree.getCell(1,0),
gridThreeThree.getCell(1,1)); // gridThreeThree.getCell(1,1));
List<Cell> fromIteratorCells = new ArrayList<>(); // List<Cell> fromIteratorCells = new ArrayList<>();
for(;redCellIterator.hasNext();) fromIteratorCells.add(redCellIterator.next()); // for(;redCellIterator.hasNext();) fromIteratorCells.add(redCellIterator.next());
assertThat(fromIteratorCells).hasSameElementsAs(expectedRedCells).hasSameSizeAs(expectedRedCells); // assertThat(fromIteratorCells).hasSameElementsAs(expectedRedCells).hasSameSizeAs(expectedRedCells);
//
ColoredCellIterator blackCellIterator = new ColoredCellIterator(gridThreeThree.getCell(2,1)); // ColoredCellIterator blackCellIterator = new ColoredCellIterator(gridThreeThree.getCell(2,1));
List<Cell> expectedBlackCells = List.of(gridThreeThree.getCell(2,0), // List<Cell> expectedBlackCells = List.of(gridThreeThree.getCell(2,0),
gridThreeThree.getCell(2,1)); // gridThreeThree.getCell(2,1));
fromIteratorCells = new ArrayList<>(); // fromIteratorCells = new ArrayList<>();
for( ; blackCellIterator.hasNext(); ) fromIteratorCells.add(blackCellIterator.next()); // for( ; blackCellIterator.hasNext(); ) fromIteratorCells.add(blackCellIterator.next());
assertThat(fromIteratorCells).hasSameElementsAs(expectedBlackCells).hasSameSizeAs(expectedBlackCells); // assertThat(fromIteratorCells).hasSameElementsAs(expectedBlackCells).hasSameSizeAs(expectedBlackCells);
//
} // }
//
} //}
\ No newline at end of file \ 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