From e172cdd45b02d65fb03bd860fdb0b7ef37ddf553 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 26 Jun 2024 22:05:52 +0200 Subject: [PATCH] tout ca tout ca --- .../but3/dev6_2/EightQueensSolver.java | 16 ++-- .../but3/dev6_2/ChessboardTest.java | 81 +++++++++++++++++-- .../steps/EightQueensSolverStepsTest.java | 24 ++++++ 3 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 src/test/java/fr/iut_fbleau/but3/dev6_2/steps/EightQueensSolverStepsTest.java diff --git a/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java b/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java index 70f7f56..578c438 100644 --- a/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java +++ b/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java @@ -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(); System.out.println("Début SimSim"); - System.out.println(SolverSim(0)); + System.out.println(solver.SolverSim(0)); System.out.println("Fin SimSim"); long endTimeSimSim = System.currentTimeMillis(); 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(); System.out.println("Début Victor"); - System.out.println(Solver(0)); + System.out.println(solver.Solver(0)); System.out.println("Fin Victor"); long endTimeVictor = System.currentTimeMillis(); System.out.println("Temps d'exécution Victor: " + (endTimeVictor - startTimeVictor) + " ms"); - chessboard.printChessboard(); + solver.chessboard.printChessboard(); } diff --git a/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java b/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java index d1c8384..5caa59c 100644 --- a/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java +++ b/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java @@ -1,6 +1,8 @@ package fr.iut_fbleau.but3.dev6_2; 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.Test; @@ -9,15 +11,84 @@ class ChessboardTest { private Chessboard chessboard; @BeforeEach - public void beforeEach(){ + public void beforeEach() { this.chessboard = new Chessboard(); } @Test - void placeAQueen(){ - this.chessboard.placeQueen(0,0); - assertEquals(1, this.chessboard.getNumberOfQueen()); + void testReplaceQueen() { + //test place une reine + this.chessboard.placeQueen(0, 0); + 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); -} \ No newline at end of file + 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."); + } + } + + +} diff --git a/src/test/java/fr/iut_fbleau/but3/dev6_2/steps/EightQueensSolverStepsTest.java b/src/test/java/fr/iut_fbleau/but3/dev6_2/steps/EightQueensSolverStepsTest.java new file mode 100644 index 0000000..f790141 --- /dev/null +++ b/src/test/java/fr/iut_fbleau/but3/dev6_2/steps/EightQueensSolverStepsTest.java @@ -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()); + } + +} \ No newline at end of file