first commit de mes deux
This commit is contained in:
commit
0b8f7c5a76
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
49
README.MD
Normal file
49
README.MD
Normal file
@ -0,0 +1,49 @@
|
||||
# Problème des Huit Dames
|
||||
|
||||
## Préambule
|
||||
|
||||
La moyenne de votre classe concernant mon module sont très mauvaises **(7 de moyenne)**. Je vous propose donc un exercice optionnel qui a pour **date limite de rendu le 28 juin**. **Il sera coefficient 0.75** (le projet était coefficient 1).
|
||||
|
||||
## La méthode d'évaluation est la suivante :
|
||||
|
||||
* La qualité de code (7 points)
|
||||
* Vérification par le lancement des tests :
|
||||
* les tests unitaires (7 points)
|
||||
* les tests Cucumber (6 points)
|
||||
|
||||
## Description
|
||||
|
||||
Le problème des huit dames est un puzzle classique qui consiste à placer huit reines sur un échiquier de 8x8 de manière à ce qu'aucune reine ne puisse en attaquer une autre. Les règles sont les suivantes :
|
||||
- Une reine peut attaquer toute pièce se trouvant sur la même ligne, colonne ou diagonale qu'elle.
|
||||
- Aucune des huit reines ne doit être en position d'attaquer une autre reine.
|
||||
|
||||
## Objectif
|
||||
|
||||
L'objectif de cet exercice est de trouver une solution au problème des huit dames en utilisant des tests unitaires et des tests de comportement dirigé par le développement (BDD) avec Cucumber.
|
||||
|
||||
## Installation
|
||||
|
||||
0. Installation maven :
|
||||
* Windows simple : https://community.chocolatey.org/packages/maven
|
||||
* Mac simple : https://mkyong.com/maven/install-maven-on-mac-osx/
|
||||
* Installation normal (Mac, Windows, Linux) : https://www.baeldung.com/install-maven-on-windows-linux-mac
|
||||
|
||||
1. Clonez ce dépôt :
|
||||
```bash
|
||||
git clone https://github.com/MaximePIERRONT/optional-java-bdd-exercice
|
||||
cd optional-java-bdd-exercice
|
||||
```
|
||||
|
||||
2. Construisez le projet avec Maven :
|
||||
```bash
|
||||
mvn clean install
|
||||
```
|
||||
|
||||
## Exécution des tests
|
||||
|
||||
Pour exécuter les tests unitaires et les tests Cucumber, utilisez la commande suivante :
|
||||
```bash
|
||||
mvn test
|
||||
```
|
||||
|
||||
|
57
pom.xml
Normal file
57
pom.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>fr.iut_fbleau.but3.dev6_2</groupId>
|
||||
<artifactId>optional-java-bdd-exercice</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<junit-jupiter.version>5.10.2</junit-jupiter.version>
|
||||
<junit-platform-suite.version>1.10.1</junit-platform-suite.version>
|
||||
<cucumber.version>7.18.0</cucumber.version>
|
||||
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-suite</artifactId>
|
||||
<version>${junit-platform-suite.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-junit-platform-engine</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
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
|
Loading…
Reference in New Issue
Block a user