From c0bdf8543432030611d248e3e0791165f486947c Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 26 Jun 2024 22:49:23 +0200 Subject: [PATCH] tout ca tout ca --- .../java/fr/iut_fbleau/but3/dev6_2/Chessboard.java | 6 +++++- .../fr/iut_fbleau/but3/dev6_2/ChessboardTest.java | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java b/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java index 7959664..d9a4d73 100644 --- a/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java +++ b/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java @@ -5,7 +5,7 @@ import java.util.List; public class Chessboard { public static final int SIZE = 8; - public final int[][] gameBoard = new int[SIZE][SIZE]; + private final int[][] gameBoard = new int[SIZE][SIZE]; private final List queensPosition = new ArrayList<>(); private static final String ANSI_RED = "\u001B[31m"; private static final String ANSI_RESET = "\u001B[0m"; @@ -14,6 +14,10 @@ public class Chessboard { // Constructeur vide } + public int getTile(int x,int y){ + return gameBoard[x][y]; + } + public void placeQueen(int x, int y) { if(VerifAccessible(x,y)){ gameBoard[x][y] = 1; 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 fb7c4d1..e7ecfa0 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 @@ -39,6 +39,16 @@ class ChessboardTest { this.chessboard.placeQueen(1, 2); this.chessboard.placeQueen(2, 4); assertEquals(3, this.chessboard.getNumberOfQueen()); + int cpt=0; + //double test to assure getNumberOfQueen works + for(int i = 0; i< Chessboard.SIZE ;i++){ + for(int j = 0; j< Chessboard.SIZE ;j++){ + if(this.chessboard.getTile(i, j) == 1){ + cpt += 1; +; } + } + } + assertEquals(3, cpt); } @Test @@ -81,7 +91,7 @@ class ChessboardTest { assertEquals(Chessboard.SIZE, chessboard.getNumberOfQueen(),"Devrait etre egal a "+Chessboard.SIZE); for(int i = 0; i< Chessboard.SIZE ;i++){ for(int j = 0; j< Chessboard.SIZE ;j++){ - if(chessboard.gameBoard[i][j] != 0){ + if(chessboard.getTile(i,j) != 0){ chessboard.removeQueen(i,j); assertTrue(chessboard.VerifAccessible(i,j)); chessboard.placeQueen(i,j);