Skip to content
Snippets Groups Projects
Commit 6c04e46e authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Added tests for ArrayGrid

parent 9ebe126e
No related branches found
No related tags found
No related merge requests found
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;
public class ArrayGridTest {
Grid arrayGridThreeTimesFour;
@BeforeEach
void initializeGrid(){
arrayGridThreeTimesFour = new ArrayGrid(3, 4);
}
@Test
void testGetNumberOfRows(){
assertThat(arrayGridThreeTimesFour.getNumberOfRows()).isEqualTo(3);
}
@Test
void testGetNumberOfColumns(){
assertThat(arrayGridThreeTimesFour.getNumberOfColumns()).isEqualTo(4);
}
@Test
void testSquaresAreNotNull_afterConstruction(){
for(int row = 0; row < arrayGridThreeTimesFour.getNumberOfRows(); row++)
for(int column = 0; column < arrayGridThreeTimesFour.getNumberOfColumns(); column++)
assertThat(arrayGridThreeTimesFour.getSquare(row,column)).isNotNull();
}
@Test
void testNeighbor(){
Square square22 = arrayGridThreeTimesFour.getSquare(2,2);
assertThat(square22.getNeighbor(CardinalDirection.NORTH))
.isEqualTo(arrayGridThreeTimesFour.getSquare(1, 2));
assertThat(square22.getNeighbor(CardinalDirection.EAST))
.isEqualTo(arrayGridThreeTimesFour.getSquare(2, 3));
assertThat(square22.getNeighbor(CardinalDirection.SOUTH))
.isEqualTo(EmptySquare.EMPTY_SQUARE);
assertThat(square22.getNeighbor(CardinalDirection.WEST))
.isEqualTo(arrayGridThreeTimesFour.getSquare(2, 1));
}
@Test
void testFill(){
Tile redTile = new UniformTile(new ColoredSide(Color.RED));
arrayGridThreeTimesFour.fill(square -> redTile);
for(int row = 0; row < arrayGridThreeTimesFour.getNumberOfRows(); row++)
for(int column = 0; column < arrayGridThreeTimesFour.getNumberOfColumns(); column++)
assertThat(arrayGridThreeTimesFour.getSquare(row,column).getTile()).isEqualTo(redTile);
}
@Test
void testIterator(){
Iterator<Square> iterator = arrayGridThreeTimesFour.iterator();
assertThat(iterator.hasNext()).isTrue();
for(int row = 0; row < arrayGridThreeTimesFour.getNumberOfRows(); row++) {
for (int column = 0; column < arrayGridThreeTimesFour.getNumberOfColumns(); column++) {
assertThat(iterator.next()).isEqualTo(arrayGridThreeTimesFour.getSquare(row, column));
}
}
assertThat(iterator.hasNext()).isFalse();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment