first commit de mes deux
This commit is contained in:
24
src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java
Normal file
24
src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Chessboard {
|
||||
private static final int SIZE = 8;
|
||||
private final int[][] gameBoard = new int[SIZE][SIZE];
|
||||
|
||||
private final List<Position> queensPosition = new ArrayList<>();
|
||||
|
||||
public Chessboard(){
|
||||
|
||||
}
|
||||
|
||||
public void placeQueen(int x, int y){
|
||||
gameBoard[x][y] = 1;
|
||||
queensPosition.add(new Position(x,y));
|
||||
}
|
||||
|
||||
public int getNumberOfQueen() {
|
||||
return queensPosition.size();
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
public class EightQueensSolver {
|
||||
private Chessboard chessboard = new Chessboard();
|
||||
|
||||
public EightQueensSolver(){
|
||||
|
||||
}
|
||||
|
||||
public Chessboard getChessboard() {
|
||||
return chessboard;
|
||||
}
|
||||
}
|
4
src/main/java/fr/iut_fbleau/but3/dev6_2/Position.java
Normal file
4
src/main/java/fr/iut_fbleau/but3/dev6_2/Position.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
public record Position(int x, int y) {
|
||||
}
|
22
src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java
Normal file
22
src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ChessboardTest {
|
||||
|
||||
private Chessboard chessboard;
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach(){
|
||||
this.chessboard = new Chessboard();
|
||||
}
|
||||
|
||||
@Test
|
||||
void placeAQueen(){
|
||||
this.chessboard.placeQueen(0,0);
|
||||
assertEquals(1, this.chessboard.getNumberOfQueen());
|
||||
}
|
||||
}
|
15
src/test/java/fr/iut_fbleau/but3/dev6_2/CucumberTest.java
Normal file
15
src/test/java/fr/iut_fbleau/but3/dev6_2/CucumberTest.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
import org.junit.platform.suite.api.ConfigurationParameter;
|
||||
import org.junit.platform.suite.api.IncludeEngines;
|
||||
import org.junit.platform.suite.api.SelectClasspathResource;
|
||||
import org.junit.platform.suite.api.Suite;
|
||||
|
||||
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
|
||||
|
||||
@Suite
|
||||
@IncludeEngines("cucumber")
|
||||
@SelectClasspathResource("features")
|
||||
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "fr.iut_fbleau.but3.dev6_2.steps")
|
||||
public class CucumberTest {
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class EightQueensSolverTest {
|
||||
|
||||
private EightQueensSolver eightQueensSolver;
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach(){
|
||||
this.eightQueensSolver = new EightQueensSolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getChessBoardOfSolver(){
|
||||
Chessboard chessboard = this.eightQueensSolver.getChessboard();
|
||||
assertNotNull(chessboard);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package fr.iut_fbleau.but3.dev6_2.steps;
|
||||
|
||||
import fr.iut_fbleau.but3.dev6_2.EightQueensSolver;
|
||||
import io.cucumber.java.en.Given;
|
||||
import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class EightQueensSolverSteps {
|
||||
private EightQueensSolver eightQueensSolver;
|
||||
|
||||
@Given("un echiquier")
|
||||
public void unEchiquier() {
|
||||
this.eightQueensSolver = new EightQueensSolver();
|
||||
}
|
||||
|
||||
@When("placer une reine en {int}, {int}")
|
||||
public void placerUnReineEn(int x, int y) {
|
||||
this.eightQueensSolver.getChessboard().placeQueen(x,y);
|
||||
}
|
||||
|
||||
@Then("{int} reine sur l'échiquier")
|
||||
public void reineSurLEchiquier(int queensOnChessboard) {
|
||||
assertEquals(1, this.eightQueensSolver.getChessboard().getNumberOfQueen());
|
||||
}
|
||||
}
|
7
src/test/resources/features/placeAQueen.feature
Normal file
7
src/test/resources/features/placeAQueen.feature
Normal file
@@ -0,0 +1,7 @@
|
||||
Feature: Placer une reine
|
||||
Placer une reine sur l'échiquier
|
||||
|
||||
Scenario: Placer une reine en 0, 0
|
||||
Given un echiquier
|
||||
When placer une reine en 0, 0
|
||||
Then 1 reine sur l'échiquier
|
Reference in New Issue
Block a user