Commit 0be53cd4 authored by noel5550's avatar noel5550

Fin des tests, debut redaction du rapport

parent f00bf51e
:sectnums:
= Rapport
== Testabilité
== Mutations
= A very simple game
== Introduction
......
......@@ -2,13 +2,18 @@ package simpleGame.cli;
import java.util.Scanner;
import simpleGame.core.Board;
import simpleGame.core.Direction;
import simpleGame.core.Game;
import simpleGame.core.Pawn;
import simpleGame.exception.OutOfBoardException;
public class CLIMain {
private static Game game;
private static Board board;
private static Pawn pawn1;
private static Pawn pawn2;
public static void main(String[] args) {
......
......@@ -188,5 +188,10 @@ public class Pawn {
return this.hitpoints == 0;
}
public int getHitpoints() {
return hitpoints;
}
}
......@@ -223,6 +223,17 @@ public class BoardT {
//Test de sprite en dehors du board, donc un point
str = board.squareContentSprite(25, 25);
assertEquals("⋅",str);
}
}
@Test
public void boardGetterTest(){
//Size
board = new Board(2,6,5,2,1);
assertEquals(6,board.getxSize());
assertEquals(5,board.getySize());
assertEquals(2,board.getxBonusSquare());
assertEquals(1,board.getyBonusSquare());
}
}
......@@ -5,8 +5,11 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import simpleGame.core.Board;
import simpleGame.core.Direction;
import simpleGame.core.Game;
import simpleGame.core.Pawn;
import simpleGame.exception.OutOfBoardException;
import simpleGame.util.StringColoring;
import static org.junit.jupiter.api.Assertions.*;
......@@ -20,22 +23,94 @@ public class GameT {
//Reset avant chaque test
@BeforeEach
public void setup(){
game = new Game();
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);
//Jeu se termine avec 3 gold
pawn1.setGold(1);
pawn2.setGold(3);
game.getBoard().addPawn(pawn1);
game.getBoard().addPawn(pawn2);
assertTrue(game.isGameOver());
//jeu ne se termine pas avec <3 gold
pawn1.setGold(1);
pawn2.setGold(2);
game.getBoard().addPawn(pawn1);
game.getBoard().addPawn(pawn2);
assertFalse(game.isGameOver());
}
@Test
public void gameEndPawnNumberTest(){
//game over avec 1 pawn seulement
game.setBoard(board);
game.getBoard().addPawn(pawn1);
assertTrue(game.isGameOver());
//Game pas over avec 2 pawns
board.removeAllPawns();
game.setBoard(board);
game.getBoard().addPawn(pawn1);
game.getBoard().addPawn(pawn2);
assertFalse(game.isGameOver());
}
@Test
public void gamePawnMovementTest() throws OutOfBoardException{
//Faire en sorte que les pawns soient cote à cote
pawn1 = new Pawn('1',1,1,board);
pawn2 = new Pawn('2',2,1,board);
board.addPawn(pawn1);
board.addPawn(pawn2);
board.setCurrentPawn(pawn1);
game.setBoard(board);
//Test pawn1 attaquant pawn2, voir que le PV du pawn2 est réduit de 1
//et les coordonnees de pawn1 soient 1;1 car il n'a pas bougé
assertEquals(pawn1.getLetter() + " attacks!\n" +
pawn2.getLetter() + " loses 1 hitpoints.",game.moveNextPawn(Direction.Right));
assertEquals(2,pawn1.getHitpoints());
assertEquals(1,pawn2.getHitpoints());
assertEquals(1,pawn1.getX());
assertEquals(1,pawn1.getY());
//test pawn2 fuyant pawn1, son pv ne change pas
//et ses coordonnees seront 3;1
assertEquals("",game.moveNextPawn(Direction.Right));
assertEquals(2,pawn1.getHitpoints());
assertEquals(1,pawn2.getHitpoints());
assertEquals(3,pawn2.getX());
assertEquals(1,pawn2.getY());
//test pour un mauvais input du mouvement pour pawn1
assertThrows(OutOfBoardException.class, () -> game.moveNextPawn(Direction.Down));
}
@Test
public void gameEndStringTest(){
board.addPawn(pawn1);
board.setCurrentPawn(pawn1);
game.setBoard(board);
String str = "⋅⋅⋅⋅\n" +
"⋅⋅⋅⋅"+"\n" +
"⋅" + StringColoring.colorString(pawn1.getLetter(), StringColoring.Color.BLUE) + "⋅⋅\n" +
"⋅⋅⋅⋅\n"+
"\n\n Game over";
assertEquals(str,game.toString());
}
}
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 simpleGame.exception.OutOfBoardException;
import static org.junit.jupiter.api.Assertions.*;
public class PawnT {
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 pawnHPTest(){
//Vérifier que pawn1 est vivant avec >0pv
pawn1.setHitpoints(2);
assertFalse(pawn1.isDead());
//Vérifier que pawn1 meurs avec 0pv
pawn1.setHitpoints(0);
assertTrue(pawn1.isDead());
}
}
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