first commit de mes deux

This commit is contained in:
Victor
2024-06-21 22:10:13 +02:00
commit 0b8f7c5a76
11 changed files with 278 additions and 0 deletions

View 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();
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,4 @@
package fr.iut_fbleau.but3.dev6_2;
public record Position(int x, int y) {
}

View 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());
}
}

View 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 {
}

View 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.assertNotNull;
class EightQueensSolverTest {
private EightQueensSolver eightQueensSolver;
@BeforeEach
public void beforeEach(){
this.eightQueensSolver = new EightQueensSolver();
}
@Test
void getChessBoardOfSolver(){
Chessboard chessboard = this.eightQueensSolver.getChessboard();
assertNotNull(chessboard);
}
}

View File

@@ -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());
}
}

View 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