Commit f00bf51e authored by noel5550's avatar noel5550

Premier push, tests Board et debut tests Game

parent 3c6ff403
......@@ -4,8 +4,14 @@
<artifactId>simpleGame</artifactId>
<version>1</version>
<build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.version>2.22.2</surefire.version>
<pitest.version>1.5.1</pitest.version>
<jacoco.version>0.8.5</jacoco.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -23,7 +29,153 @@
</archive>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.0</version>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pitest.version}</version>
<configuration>
<targetClasses>
<param>simpleGame.*</param>
</targetClasses>
<targetTests>
<param>simpleGame.*</param>
</targetTests>
</configuration>
<executions>
<execution>
<goals>
<goal>mutationCoverage</goal>
</goals>
<phase>pre-site</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.12</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pitest.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>public</show>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<version>${pitest.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -69,6 +69,8 @@ public class Board {
* @param numberOfPawns The number of pawns.
* @param sizeX The number of squares on the x axis.
* @param sizeY The number of squares on the y axis.
* @param xBonus The number of bonus on the x axis.
* @param yBonus The number of bonus on the y axis.
*/
public Board(int numberOfPawns, int sizeX, int sizeY, int xBonus, int yBonus) {
Random random = new Random();
......@@ -234,4 +236,55 @@ public class Board {
pawns.clear();
currentPawn = null;
}
public int getxSize() {
return xSize;
}
public void setxSize(int xSize) {
this.xSize = xSize;
}
public int getySize() {
return ySize;
}
public void setySize(int ySize) {
this.ySize = ySize;
}
public ArrayList<Pawn> getPawns() {
return pawns;
}
public void setPawns(ArrayList<Pawn> pawns) {
this.pawns = pawns;
}
public int getxBonusSquare() {
return xBonusSquare;
}
public void setxBonusSquare(int xBonusSquare) {
this.xBonusSquare = xBonusSquare;
}
public int getyBonusSquare() {
return yBonusSquare;
}
public void setyBonusSquare(int yBonusSquare) {
this.yBonusSquare = yBonusSquare;
}
public Pawn getCurrentPawn() {
return currentPawn;
}
public void setCurrentPawn(Pawn currentPawn) {
this.currentPawn = currentPawn;
}
}
......@@ -54,4 +54,14 @@ public class Game {
return this.board.getNextPawn().move(d);
}
public Board getBoard() {
return board;
}
public void setBoard(Board board) {
this.board = board;
}
}
......@@ -52,9 +52,31 @@ public class Pawn {
return gold;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
/**
public void setBoard(Board board) {
this.board = board;
}
public void setHitpoints(int hitpoints) {
this.hitpoints = hitpoints;
}
public void setGold(int gold) {
this.gold = gold;
}
public void setLetter(char letter) {
this.letter = letter;
}
/**
* Creates a Pawn with 2 hitpoints and 0 gold.
* @param n The letter that represents the pawn.
* @param x Position on the x axis
......
......@@ -68,6 +68,11 @@ public class StringColoring {
/**
* Overload for char parameters.
*
* @param message The message to print.
* @param color The chosen color for the message.
* @return A string prepended with the ANSI code corresponding to the chosen
* color, and appended with the ANSI color reset code.
*/
public static String colorString(char message, Color color) {
return colorString("" + message, color);
......
package simpleGame;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import simpleGame.core.Board;
import simpleGame.core.Pawn;
import simpleGame.util.StringColoring;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
public class BoardT {
private Board board;
private Pawn pawn1;
private Pawn pawn2;
//Reset avant chaque test
@BeforeEach
public void setup(){
pawn1 = new Pawn('1',1,1,board);
pawn2 = new Pawn('2',2,2,board);
board = new Board(2,4,4,4,4);
board.removeAllPawns();
}
@Test
public void boardThrowExceptionNoPawnTest() throws IndexOutOfBoundsException {
assertThrows(IndexOutOfBoundsException.class, () -> {
board = new Board(0,40,40,4,4);
});
}
@Test
public void boardThrowExceptionTooMuchPawnTest() throws IndexOutOfBoundsException {
assertThrows(NullPointerException.class, () -> {
//Un Board avec nbPions > 27 est null car getCharForNumber est null avec nbPions>27
board = new Board(27,400,400,3,3);
});
}
@Test
public void boardGetSquareTest(){
Pawn squarePawn = board.getSquareContent(2, 2);
//Assert que squarePawn est bien null
assertNull(squarePawn);
board.removeAllPawns();
//Assert que le pawn est en dehors des squares
squarePawn = board.getSquareContent(7, 7);
assertNull(squarePawn);
board.removeAllPawns();
//Assert que squarePawn a bien les pawns insérés
board.addPawn(pawn1);
squarePawn = board.getSquareContent(1, 1);
assertEquals(pawn1,squarePawn);
assertNotNull(squarePawn);
}
@Test
public void boardNumberPawnsTest() {
board = new Board(8,40,40,4,4);
assertEquals(8,board.numberOfPawns());
assertEquals('I',board.getPawns().get(7).getLetter());
}
@Test
public void boardSquareContentTest(){
//Voir que p1 (qui est mis à 1,1 est le même que squareContent, qui se trouve à 1,1
board.addPawn(pawn1);
Pawn squareContent = board.getSquareContent(1, 1);
assertNotNull(squareContent);
assertEquals(pawn1,squareContent);
}
@Test
public void boardMaxGoldTest(){
pawn1.setGold(5);
board.addPawn(pawn1);
assertEquals(5,board.maxGold());
}
@Test
public void boardNumberOfPawnsTest(){
board.addPawn(pawn1);
board.addPawn(pawn2);
assertEquals(2,board.numberOfPawns());
}
@Test
public void boardPawnListTest(){
//Vérifier avec 0 pawn en jeu
assertNull(board.getNextPawn());
//Vérifier avec un pawn en jeu
board.addPawn(pawn1);
board.setCurrentPawn(pawn1);
Pawn pawnTampon = board.getNextPawn();
assertEquals(pawn1,pawnTampon);
assertEquals(pawn1,board.getCurrentPawn());
//Ajout d'un deuxième pawn, pour qu'il y ait plus qu'un pawn dans le board
board.addPawn(pawn2);
board.setCurrentPawn(pawn1);
pawnTampon = board.getNextPawn();
assertEquals(pawn1,pawnTampon);
assertNotEquals(pawn2,pawnTampon);
assertEquals(pawn2,board.getCurrentPawn());
}
@Test
public void boardPawnRemoveTest(){
//Enlever pawn1, qui existe
board.addPawn(pawn1);
board.removePawn(pawn1);
board.removeAllPawns();
assertEquals(new ArrayList<>(),board.getPawns());
assertEquals(0,board.numberOfPawns());
//Enlever pawn 2, vérifie que pawn1 est toujours là
board.addPawn(pawn1);
board.removePawn(pawn2);
ArrayList<Pawn> pawnTabs = new ArrayList<>();
pawnTabs.add(pawn1);
assertEquals(pawnTabs,board.getPawns());
assertEquals(1,board.numberOfPawns());
}
@Test
public void boardPawnAddTest(){
board.addPawn(pawn1);
//Vérifie que pawn1 est bien ajouté
ArrayList<Pawn> pawnTabs = new ArrayList<>();
pawnTabs.add(pawn1);
assertEquals(pawnTabs,board.getPawns());
assertEquals(1,board.numberOfPawns());
}
@Test
public void boardPawnAddRemoveTest(){
board.addPawn(pawn1);
board.removePawn(pawn1);
board.addPawn(pawn2);
ArrayList<Pawn> pawnTabs = new ArrayList<>();
pawnTabs.add(pawn1);
//Vérifie que pawn1 n'est pas dans pawnTabs
assertNotEquals(pawnTabs,board.getPawns());
//Vérifie que pawn2 est dans pawnTabs et le seul a y etre
pawnTabs = new ArrayList<>();
pawnTabs.add(pawn2);
assertEquals(pawnTabs,board.getPawns());
assertEquals(1,board.numberOfPawns());
}
@Test
public void boardToStringDisplayTest(){
board.addPawn(pawn1);
board.addPawn(pawn2);
board.setCurrentPawn(pawn1);
String str = "⋅⋅⋅⋅\n" +
"⋅⋅" + pawn2.getLetter() + "⋅"+"\n" +
"⋅" + StringColoring.colorString(pawn1.getLetter(), StringColoring.Color.BLUE) + "⋅⋅\n" +
"⋅⋅⋅⋅\n";
assertEquals(str,board.toString());
}
@Test
public void boardSquareSpriteTest(){
//Ce square contient le bonus à 4, 4 (voir le BeforeEach) donc elle est de couleur jaune
String str = board.squareContentSprite(4, 4);
assertEquals(str,StringColoring.colorString('#', StringColoring.Color.YELLOW));
//Ce square n'a pas de bonus, donc pas de sprite
str = board.squareContentSprite(2, 2);
assertEquals("⋅",str);
//Test de sprite d'un pawn courantqui a un bonus
//On doit set les coordonnées de ce sprite pour qu'il soit sur le bonus
pawn1.setX(4);
pawn1.setY(4);
board.addPawn(pawn1);
board.setCurrentPawn(pawn1);
str = board.squareContentSprite(4, 4);
assertEquals(str,StringColoring.colorString(pawn1.getLetter(), StringColoring.Color.GREEN));
//Test de sprite d'un pawn curant qui n'a pas de bonus
board.addPawn(pawn2);
board.setCurrentPawn(pawn2);
str = board.squareContentSprite(2, 2);
assertEquals(str,StringColoring.colorString(pawn2.getLetter(), StringColoring.Color.BLUE));
//Test de sprite d'un pawn non courant (pawn1) qui a un bonus
str = board.squareContentSprite(4, 4);
assertEquals(str,StringColoring.colorString(pawn1.getLetter(), StringColoring.Color.YELLOW));
//Test de sprite d'un pawn non courant qui n'a pas un bonus (pawn2)
board.setCurrentPawn(pawn1);
str = board.squareContentSprite(2, 2);
assertEquals(str,String.valueOf(pawn2.getLetter()));
//Test de sprite en dehors du board, donc un point
str = board.squareContentSprite(25, 25);
assertEquals("⋅",str);
}
}
package simpleGame;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import simpleGame.core.Board;
import simpleGame.core.Game;
import simpleGame.core.Pawn;
import static org.junit.jupiter.api.Assertions.*;
public class GameT {
private Game game;
private Board board;
private Pawn pawn1;
private Pawn pawn2;
//Reset avant chaque test
@BeforeEach
public void setup(){
pawn1 = new Pawn('1',1,1,board);
pawn2 = new Pawn('2',2,2,board);
board = new Board(2,4,4,4,4);
board.removeAllPawns();
}
//Test fonctionnel
@Test
public void gameEndGoldTest(){
game.setBoard(board);
pawn1.setGold(1);
pawn2.setGold(3);
game.getBoard().addPawn(pawn1);
game.getBoard().addPawn(pawn2);
assertTrue(game.isGameOver());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment