tout ca tout ca

This commit is contained in:
Victor 2024-06-26 22:05:52 +02:00
parent 43be2c70f5
commit e172cdd45b
3 changed files with 108 additions and 13 deletions

View File

@ -9,28 +9,28 @@ public class EightQueensSolver {
public void main(String[] args){ public static void main(String[] args){
EightQueensSolver solver = new EightQueensSolver();
// Début de la résolution par méthode simplifiée
long startTimeSimSim = System.currentTimeMillis(); long startTimeSimSim = System.currentTimeMillis();
System.out.println("Début SimSim"); System.out.println("Début SimSim");
System.out.println(SolverSim(0)); System.out.println(solver.SolverSim(0));
System.out.println("Fin SimSim"); System.out.println("Fin SimSim");
long endTimeSimSim = System.currentTimeMillis(); long endTimeSimSim = System.currentTimeMillis();
System.out.println("Temps d'exécution SimSim: " + (endTimeSimSim - startTimeSimSim) + " ms"); System.out.println("Temps d'exécution SimSim: " + (endTimeSimSim - startTimeSimSim) + " ms");
chessboard.printChessboard(); solver.chessboard.printChessboard();
chessboard = new Chessboard(); // Réinitialisation du plateau solver.chessboard = new Chessboard();
// Début de la résolution par méthode classique
long startTimeVictor = System.currentTimeMillis(); long startTimeVictor = System.currentTimeMillis();
System.out.println("Début Victor"); System.out.println("Début Victor");
System.out.println(Solver(0)); System.out.println(solver.Solver(0));
System.out.println("Fin Victor"); System.out.println("Fin Victor");
long endTimeVictor = System.currentTimeMillis(); long endTimeVictor = System.currentTimeMillis();
System.out.println("Temps d'exécution Victor: " + (endTimeVictor - startTimeVictor) + " ms"); System.out.println("Temps d'exécution Victor: " + (endTimeVictor - startTimeVictor) + " ms");
chessboard.printChessboard(); solver.chessboard.printChessboard();
} }

View File

@ -1,6 +1,8 @@
package fr.iut_fbleau.but3.dev6_2; package fr.iut_fbleau.but3.dev6_2;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -14,9 +16,78 @@ class ChessboardTest {
} }
@Test @Test
void placeAQueen(){ void testReplaceQueen() {
//test place une reine
this.chessboard.placeQueen(0, 0); this.chessboard.placeQueen(0, 0);
assertEquals(1, this.chessboard.getNumberOfQueen()); assertEquals(1, this.chessboard.getNumberOfQueen(), "Il devrait y avoir 1 reine sur l'échiquier.");
assertFalse(this.chessboard.VerifAccessible(0, 0), "La position (0,0) ne devrait pas être accessible.");
// Déplacer la reine
this.chessboard.removeQueen(0, 0);
this.chessboard.placeQueen(5, 3);
assertEquals(1, this.chessboard.getNumberOfQueen(), "Il devrait y avoir 1 reine sur l'échiquier.");
assertTrue(this.chessboard.VerifAccessible(0, 0), "La position (0,0) devrait être accessible.");
assertFalse(this.chessboard.VerifAccessible(5, 3), "La position (1,1) ne devrait pas être accessible.");
}
@Test
void placeMultipleQueens() {
this.chessboard.placeQueen(0, 0);
this.chessboard.placeQueen(1, 2);
this.chessboard.placeQueen(2, 4);
assertEquals(3, this.chessboard.getNumberOfQueen());
}
@Test
void removeQueen() {
this.chessboard.placeQueen(0, 0);
this.chessboard.removeQueen(0, 0);
assertEquals(0, this.chessboard.getNumberOfQueen());
}
@Test
void verifAccessible() {
int middle = Chessboard.SIZE / 2;
this.chessboard.placeQueen(middle, middle);
for (int i = 0; i < Chessboard.SIZE; i++) {
assertFalse(this.chessboard.VerifAccessible(i, i));
assertFalse(this.chessboard.VerifAccessible(middle, i));
assertFalse(this.chessboard.VerifAccessible(i, middle));
if (isValidPosition(middle + i, middle + i)) {
assertFalse(this.chessboard.VerifAccessible(middle + i, middle + i));
}
if (isValidPosition(middle - i, middle - i)) {
assertFalse(this.chessboard.VerifAccessible(middle - i, middle - i));
}
if (isValidPosition(middle + i, middle - i)) {
assertFalse(this.chessboard.VerifAccessible(middle + i, middle - i));
}
if (isValidPosition(middle - i, middle + i)) {
assertFalse(this.chessboard.VerifAccessible(middle - i, middle + i));
}
}
}
private boolean isValidPosition(int x, int y) {
return x >= 0 && x < Chessboard.SIZE && y >= 0 && y < Chessboard.SIZE;
}
@Test
void testWinningSolution() {
// Placer les reines aux positions données
int[][] positions = {
{0, 0}, {1, 4}, {2, 7}, {3, 5},
{4, 2}, {5, 6}, {6, 1}, {7, 3}
};
for (int[] pos : positions) {
assertTrue(this.chessboard.VerifAccessible(pos[0], pos[1]),
"La position (" + pos[0] + "," + pos[1] + ") devrait être accessible.");
this.chessboard.placeQueen(pos[0], pos[1]);
assertFalse(this.chessboard.VerifAccessible(pos[0], pos[1]),
"La position (" + pos[0] + "," + pos[1] + ") ne devrait plus être accessible.");
}
} }

View File

@ -0,0 +1,24 @@
package fr.iut_fbleau.but3.dev6_2.steps;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import fr.iut_fbleau.but3.dev6_2.Chessboard;
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());
}
}