Commit 3980ed2e authored by Farah Matta's avatar Farah Matta

1er commit Test fonctionnel

parent 3c6ff403
......@@ -4,9 +4,38 @@
<artifactId>simpleGame</artifactId>
<version>1</version>
<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.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<configuration>
<targetClasses>
<param>fr.unantes.info.units.*</param>
</targetClasses>
<targetTests>
<param>fr.unantes.info.units.*</param>
</targetTests>
</configuration>
<executions>
<execution>
<goals>
<goal>mutationCoverage</goal>
</goals>
<phase>pre-site</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
......@@ -23,7 +52,190 @@
</archive>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<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>
<id>prepare-agent-exe</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report-exe</id>
<phase>site</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<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>
</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.pitest</groupId>
<artifactId>pitest</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
......@@ -78,7 +78,8 @@ public class Board {
this.yBonusSquare = yBonus;
this.pawns = new ArrayList<Pawn>();
for (int i = 1; i <= numberOfPawns; i++) {
Pawn pawn = new Pawn(getCharForNumber(i + 1), random.nextInt(xSize), random.nextInt(ySize), this);
//Correction: getCharForNumber(i) au lieu de getCharForNumber(i+1) pour avoir le Pawn A
Pawn pawn = new Pawn(getCharForNumber(i), random.nextInt(xSize), random.nextInt(ySize), this);
this.addPawn(pawn);
}
......
......@@ -21,6 +21,16 @@ public class Game {
public Game() {
board = new Board(2,4,4, new Random().nextInt(4), new Random().nextInt(4));
}
/**
* Ajout:
* Getter du board créé par le Game
* @return board
* @author Farah Matta
*/
public Board getBoard() {
return board;
}
/**
* The game is over if there is only one pawn left or if
......
......@@ -51,9 +51,22 @@ public class Pawn {
public int getGold() {
return gold;
}
/**
* Ajout:
* Getter du nombre de hitpoints
* @return entier: nombre de hitpoints
* @author Farah Matta
*/
public int getHitpoints() {
return hitpoints;
}
//Ajout: setter nb de gold points
public void setGold(int g) {
this.gold=g;
}
/**
* Creates a Pawn with 2 hitpoints and 0 gold.
* @param n The letter that represents the pawn.
......@@ -66,7 +79,8 @@ public class Pawn {
this.x = x;
this.y = y;
this.board = board;
this.hitpoints = 2;
//Correction: Pawn avec 6 hitpoints comme la spécification
this.hitpoints = 6;
this.gold = 0;
}
......
package simpleGame.core;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
public class BoardTest {
int xSize = 4;
int ySize = 5;
private ArrayList<Pawn> pawns;
private int xBonusSquare;
private int yBonusSquare;
private Board board = new Board(3,4,5,1,2);
private Board board2 = new Board(1,5,5,4,1);
private Pawn p1 = new Pawn('A',2,3,board);
private Pawn p2 = new Pawn('B',4,1,board);
private Pawn p3 = new Pawn('C',3,4,board);
@Test //Fonctionnel - Spec1
public void getXSizeTest() {
assertEquals(4,board.getXSize());
}
@Test //Fonctionnel - Spec1
public void getYSizeTest() {
assertEquals(5,board.getYSize());
}
@Test //Fonctionnel - Spec1
public void isBonusSquareTest() {
assertTrue(board.isBonusSquare(1, 2));
}
@Test //Fonctionnel - Spec1
public void numberOfPawnsTest() {
assertEquals(3,board.numberOfPawns());
}
@Test //Fonctionnel - Spec2
public void getNextPawnTest() {
assertEquals(p1.getLetter(),board.getNextPawn().getLetter());
assertEquals(p2.getLetter(),board.getNextPawn().getLetter());
assertEquals(p1.getLetter(),board2.getNextPawn().getLetter());
board2.removeAllPawns();
assertEquals(null,board2.getNextPawn());
}
}
package simpleGame.core;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import simpleGame.exception.OutOfBoardException;
public class GameTest {
Game game = new Game();
Board b = game.getBoard();
Game game1 = new Game();
Board b2 = game1.getBoard();
private Pawn p1 = new Pawn('A',1,1,b);
private Pawn p2 = new Pawn('B',2,1,b);
/*@Test //Fonctionnel - Spec3
public void moveNextPawnTest() throws OutOfBoardException {
b.removeAllPawns();
b.addPawn(p1);
b.addPawn(p2);
System.out.print("AFFICHAGE p1: " +b.isBonusSquare(p1.getX(), p1.getY()));
String m="A attacks!\\n ";
if(b.isBonusSquare(p1.getX(), p1.getY())) {
m+="B loses 2 hitpoints.";
}
else {
m+="B loses 1 hitpoints.";
}
assertEquals(m,game.moveNextPawn(Direction.Right));
}*/
@Test //Fonctionnel - Spec6
public void isGameOverTest() {
b.removeAllPawns();
b.addPawn(p1);
assertTrue(game.isGameOver());
}
@Test //Fonctionnel - Spec6
public void isGameOverTest2() {
b2.removeAllPawns();
b2.addPawn(p1);
b2.addPawn(p2);
assertFalse(game1.isGameOver());
p2.setGold(3);
assertTrue(game1.isGameOver());
}
}
package simpleGame.core;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import simpleGame.exception.OutOfBoardException;
public class PawnTest {
private Board board = new Board(3,5,5,2,3);
private Pawn pawn = new Pawn('F',1,2,board);
@Test //Fonctionnel - Spec2
public void getLetterTest() {
assertEquals('F',pawn.getLetter());
}
@Test //Fonctionnel - Spec3
public void moveTest() throws OutOfBoardException {
board.removeAllPawns();
Pawn p = new Pawn('A',3,3,board);
board.addPawn(p);
p.move(Direction.Left);
assertTrue(p.getX()==2);
p.move(Direction.Up);
assertTrue(p.getY()==4);
p.move(Direction.Down);
assertTrue(p.getY()==3);
p.move(Direction.Right);
assertTrue(p.getX()==3);
}
@Test //Fonctionnel - Spec5
public void getHitpointsTest() {
assertEquals(6,pawn.getHitpoints());
}
}
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