package fr.iut_fbleau.Tests; import fr.iut_fbleau.GameAPI.AbstractPly; import fr.iut_fbleau.GameAPI.Player; import fr.iut_fbleau.Avalam.AvalamBoard; import fr.iut_fbleau.Avalam.AvalamPly; import fr.iut_fbleau.Avalam.Tower; import fr.iut_fbleau.Avalam.Color; import org.junit.Before; import org.junit.Test; //import org.mockito.Mockito; //Mockito absent import static org.junit.Assert.*; /** * La classe AvalamBoardTest test si la méthode isLegal() fonctionne comme prévu. */ public class AvalamBoardTest { private Tower[][] grid; private AvalamBoard board; @Before public void setUp() { grid = new Tower[AvalamBoard.SIZE][AvalamBoard.SIZE]; //Création des tours de tests /* Motif 1,0,2 | 2,0,3 2,1,0 | 2,3,0 0,2,1 | 0,1,1 */ grid[4][2] = new Tower(2, Color.YELLOW); grid[6][2] = new Tower(3, Color.RED); grid[4][3] = new Tower(2, Color.RED); grid[5][3] = new Tower(3, Color.YELLOW); grid[5][4] = new Tower(1, Color.RED); grid[6][4] = new Tower(1, Color.YELLOW); //Joueur courant initialisé à 1, soit jaune board = new AvalamBoard(grid); //AvalamBoard copie la grille } /* @Test //Mockito absent public void nonAvalamPly_returnsFalse() { //Vérifie si l'instance est bien AvalamPly AbstractPly fake = Mockito.mock(AbstractPly.class); //Crée une instance non-AvalamPly assertFalse(board.isLegal(fake)); }*/ @Test public void outOfBounds_returnsFalse() { //Source "out of box" AvalamPly p = new AvalamPly(Player.PLAYER1, -1, 2, 4, 2); assertFalse(board.isLegal(p)); //Destination "out of box" AvalamPly p2 = new AvalamPly(Player.PLAYER1, 6, 4, 9, 4); assertFalse(board.isLegal(p2)); } @Test public void sameCell_returnsFalse() { AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 4, 5, 4); assertFalse(board.isLegal(p)); } @Test public void emptySourceOrDest_returnsFalse() { //Source null AvalamPly p1 = new AvalamPly(Player.PLAYER1, 5, 5, 5, 4); assertFalse(board.isLegal(p1)); //Destination null AvalamPly p2 = new AvalamPly(Player.PLAYER1, 6, 4, 6, 3); assertFalse(board.isLegal(p2)); } @Test public void sourceNotOwned_returnsFalse() { //Le joueur courant n'est pas rouge AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 4, 6, 4); assertFalse(board.isLegal(p)); } @Test public void notAdjacent_returnsFalse() { AvalamPly p = new AvalamPly(Player.PLAYER1, 4, 2, 6, 2); assertFalse(board.isLegal(p)); } @Test public void sameColor_returnsFalse() { //La couleur des tours est identique AvalamPly p = new AvalamPly(Player.PLAYER1, 4, 2, 5, 3); assertFalse(board.isLegal(p)); } @Test public void tooTallAfterMerge_returnsFalse() { //Hauteur maximale dépassé : 3+3 = 6 > MAX_HEIGHT (5) AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 3, 6, 2); assertFalse(board.isLegal(p)); } @Test public void validMove_returnsTrue() { AvalamPly p = new AvalamPly(Player.PLAYER1, 5, 3, 4, 3); //Hauteur limite à 5 assertTrue(board.isLegal(p)); } @Test //À vérifier public void currentPlayerMismatchInPlyDoesNotAffectOwnershipCheck() { //Si le coup est construit avec le mauvais joueur AvalamPly p = new AvalamPly(Player.PLAYER2, 4, 2, 4, 3); assertFalse(board.isLegal(p)); } }