Commit 18461347 authored by Farah Matta's avatar Farah Matta

Test structurel fini

parent 0fd7836a
File added
......@@ -215,9 +215,9 @@ public class Board {
*/
public String toString() {
String result = "";
for (int y = ySize - 1; y >= 0; y--) {
for (int x = 0; x < xSize; x++) {
//Correction: faire les parcours de 1 au size et non pas de 0 à size-1 pour correspondre au squareContent
for (int y = ySize; y > 0; y--) {
for (int x = 1; x <= xSize; x++) {
result += squareContentSprite(x, y);
if (x == xSize) {
result += '|';
......
......@@ -67,6 +67,11 @@ public class Pawn {
this.gold=g;
}
//Ajout: setter nb de gold points
public void setHitpoints(int h) {
this.hitpoints=h;
}
/**
* Creates a Pawn with 2 hitpoints and 0 gold.
......
......@@ -18,8 +18,9 @@ public class StringColoring {
/**
* Supported colors.
*/
//Correction: Ajout du Default pour pouvoir allez dans le cas par défaut
public enum Color {
BLACK, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, WHITE
BLACK, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, WHITE, DEFAULT
}
/**
......@@ -52,8 +53,10 @@ public class StringColoring {
case WHITE:
outString = ANSI_WHITE;
break;
//Correction le cas BLACK prend la couleur blue
case BLACK:
outString = ANSI_BLUE;
outString = ANSI_BLACK;
//outString = ANSI_BLUE;
break;
case YELLOW:
outString = ANSI_YELLOW;
......
package simpleGame.cli;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import simpleGame.exception.OutOfBoardException;
public class CLIMainTest {
/*
@Test public void mainTest() throws FileNotFoundException{
String[] args = null;
final InputStream original = System.in;
final FileInputStream fips = new FileInputStream(new File("/Users/farah/Documents/Université/M2Isi/vv/rappSimpleGame/test.txt"));
System.setIn(fips);
CLIMain.main(args);
System.setIn(original);
}*/
}
......@@ -8,6 +8,9 @@ import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import simpleGame.exception.OutOfBoardException;
import simpleGame.util.StringColoring;
public class BoardTest {
int xSize = 4;
int ySize = 5;
......@@ -16,11 +19,11 @@ public class BoardTest {
private int xBonusSquare;
private int yBonusSquare;
private Board board = new Board(3,4,5,1,2);
private Board board = new Board(2,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);
//private Pawn p3 = new Pawn('C',3,4,board);
@Test //Fonctionnel - Spec1
public void getXSizeTest() {
......@@ -35,22 +38,90 @@ public class BoardTest {
@Test //Fonctionnel - Spec1
public void isBonusSquareTest() {
assertTrue(board.isBonusSquare(1, 2));
assertFalse(board.isBonusSquare(1, 3));
assertFalse(board2.isBonusSquare(1, 2));
}
@Test //Fonctionnel - Spec1
public void numberOfPawnsTest() {
assertEquals(3,board.numberOfPawns());
board.removeAllPawns();
board.addPawn(p1);
board.addPawn(p2);
assertEquals(2,board.numberOfPawns());
}
@Test //Fonctionnel - Spec2
public void getNextPawnTest() {
public void getNextPawnTest() throws OutOfBoardException {
assertEquals(p1.getLetter(),board.getNextPawn().getLetter());
p1.move(Direction.Up);
assertEquals(p2.getLetter(),board.getNextPawn().getLetter());
assertEquals(p1.getLetter(),board2.getNextPawn().getLetter());
board2.removeAllPawns();
assertEquals(null,board2.getNextPawn());
}
@Test //Structurel
public void squareContentSpriteTestBonusRempli() {
Board b1 = new Board(3,5,5,1,2);
b1.removeAllPawns();
Pawn p = new Pawn('A', 1, 2, b1);
b1.addPawn(p);
assertEquals(StringColoring.colorString('A',StringColoring.Color.YELLOW ),b1.squareContentSprite(1,2));
}
@Test //Structurel
public void squareContentSpriteTestBonusVide() {
Board b1 = new Board(3,5,5,1,2);
b1.removeAllPawns();
Pawn p = new Pawn('A', 3, 2, b1);
b1.addPawn(p);
assertEquals(StringColoring.colorString('#',StringColoring.Color.YELLOW ),b1.squareContentSprite(1,2));
}
@Test //Structurel
public void squareContentSpriteTestTour() {
Board b1 = new Board(3,5,5,1,2);
b1.removeAllPawns();
Pawn p = new Pawn('A', 5, 2, b1);
//Pawn q = new Pawn('B', 3, 2, b1);
b1.addPawn(p);
assertTrue(b1.getNextPawn() == p);
assertEquals(StringColoring.colorString('A',StringColoring.Color.BLUE ),b1.squareContentSprite(5,2));
}
@Test //Structurel
public void squareContentSpriteTestTourBonus() {
Board b1 = new Board(3,5,5,1,2);
b1.removeAllPawns();
Pawn p = new Pawn('A', 1, 2, b1);
//Pawn q = new Pawn('B', 1, 2, b);
b1.addPawn(p);
assertTrue(b1.getNextPawn() == p);
assertEquals(StringColoring.colorString('A',StringColoring.Color.GREEN ),b1.squareContentSprite(1,2));
}
@Test //Structurel
public void squareContentSpriteTest() {
Board b1 = new Board(3,5,5,3,2);
b1.removeAllPawns();
Pawn p = new Pawn('A', 1, 2, b1);
b1.addPawn(p);
assertEquals("A",b1.squareContentSprite(1,2));
}
@Test
public void toStringTestBoard() {
Board b = new Board(1,2,2,2,2);
Pawn p4 = new Pawn('A',2,1,b);
b.removeAllPawns();
b.addPawn(p4);
String chaine =b.toString();
//assertTrue(board.toString().contains("B|"));
assertEquals("⋅" + StringColoring.colorString('#',StringColoring.Color.YELLOW )+ "|" + "\n" +
"⋅"+"A"+ "|" + "\n" ,chaine);
}
}
......@@ -55,5 +55,49 @@ public class GameTest {
assertTrue(game1.isGameOver());
}
@Test //Structurel
public void toStringTest() {
Game game1 = new Game();
Board b1 = game1.getBoard();
assertFalse(game1.toString().contains("\n\n Game over"));
b1.removePawn(b1.getNextPawn());
assertTrue(game1.toString().contains("\n\n Game over"));
}
@Test //Structurel
public void moveNextPawnTest() throws OutOfBoardException {
String chaine="";
try {
int x =game.getBoard().getNextPawn().getX();
int y= game.getBoard().getNextPawn().getY();
Pawn p= game.getBoard().getSquareContent(x+1, y);
if(null==p) {
chaine =game.moveNextPawn(Direction.Right);
assertTrue(chaine=="");
}
else {
boolean bonus = game.getBoard().isBonusSquare(x, y);
if(bonus) {
chaine =game.moveNextPawn(Direction.Right);
assertTrue("A attacks!" + "\n"
+ "B loses 2 hitpoints."==chaine);
}
else {
chaine =game.moveNextPawn(Direction.Right);
assertTrue("A attacks!" + "\n"
+ "B loses 1 hitpoints."==chaine);
}
}
//chaine =game.moveNextPawn(Direction.Right);
//fail("someMethod failed to throw NullPointerException for null arg");
}
catch (OutOfBoardException expected){
System.out.print("This square does not exist: " );
}
//String chaine =game.moveNextPawn(Direction.Right);
//assertFalse(chaine=="");
}
}
......@@ -43,7 +43,9 @@ public class PawnTest {
Pawn p2= new Pawn('B',2,3,board);
board.addPawn(p);
board.addPawn(p2);
p.move(Direction.Left);
String chaine= p.move(Direction.Left);
assertEquals("A attacks!" + "\n"
+ "B loses 1 hitpoints.",chaine);
}
@Test //Fonctionnel - Spec4
......@@ -56,8 +58,106 @@ public class PawnTest {
p.move(Direction.Right);
p.move(Direction.Right);
p.move(Direction.Right);
assertEquals(1,p.getGold());
}
@Test //Fonctionnel - Spec4
public void attackTestout() throws OutOfBoardException {
//Board b= new Board(2,4,4,1,2);
board.removeAllPawns();
Pawn p = new Pawn('A',4,4,board);
//Pawn p2= new Pawn('B',3,3,board);
board.addPawn(p);
//board.addPawn(p2);
p.move(Direction.Right);
}
@Test //Structurel
public void attackTestSizeY() throws OutOfBoardException {
//Board b= new Board(2,4,4,1,2);
board.removeAllPawns();
Pawn p = new Pawn('A',4,4,board);
board.addPawn(p);
p.move(Direction.Up);
}
@Test //Structurel
public void attackTestSizeX() throws OutOfBoardException {
//Board b= new Board(2,4,4,1,2);
board.removeAllPawns();
Pawn p = new Pawn('A',3,3,board);
board.addPawn(p);
p.move(Direction.Right);
}
@Test //Structurel
public void attackTestSizeXLeft() throws OutOfBoardException {
//Board b= new Board(2,4,4,1,2);
board.removeAllPawns();
Pawn p = new Pawn('A',2,1,board);
board.addPawn(p);
p.move(Direction.Left);
}
@Test //Structurel
public void attackTestSizeYNeg() throws OutOfBoardException {
board.removeAllPawns();
Pawn p = new Pawn('A',1,1,board);
board.addPawn(p);
try {
p.move(Direction.Down);
fail("someMethod failed to throw NullPointerException for null arg");
}
catch (OutOfBoardException expected){
System.out.print("This square does not exist: " + p.getX( )+"," + p.getY());
}
}
@Test //Structurel
public void attackTestSizeXNeg() throws OutOfBoardException {
board.removeAllPawns();
Pawn p = new Pawn('A',1,1,board);
board.addPawn(p);
try {
p.move(Direction.Left);
fail("someMethod failed to throw NullPointerException for null arg");
}
catch (OutOfBoardException expected){
System.out.print("This square does not exist: " + p.getX( )+"," + p.getY());
}
}
@Test //Structurel
public void attackTestSizeXY() throws OutOfBoardException {
board.removeAllPawns();
Pawn p = new Pawn('A',5,5,board);
board.addPawn(p);
try {
p.move(Direction.Right);
fail("someMethod failed to throw NullPointerException for null arg");
}
catch (OutOfBoardException expected){
System.out.print("This square does not exist: " + p.getX( )+"," + p.getY());
}
}
@Test //Structurel
public void sufferTestBonus() throws OutOfBoardException {
board.removeAllPawns();
Pawn p = new Pawn('A',2,3,board);
Pawn p2= new Pawn('B',3,3,board);
board.addPawn(p);
board.addPawn(p2);
p2.setHitpoints(1);
String chaine= p.move(Direction.Right);
assertEquals("A attacks!" + "\n"
+ "B loses 2 hitpoints.B is dead.",chaine);
assertEquals(null,board.getSquareContent(3, 3));
}
/*@Test //Fonctionnel - Spec3
public void moveTest2() throws OutOfBoardException {
board.removeAllPawns();
......@@ -73,5 +173,13 @@ public class PawnTest {
public void getHitpointsTest() {
assertEquals(6,pawn.getHitpoints());
}
@Test //Structurel
public void isDead() {
board.removeAllPawns();
Pawn p = new Pawn('A',5,5,board);
board.addPawn(p);
assertFalse(p.isDead());
}
}
package simpleGame.util;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.awt.Color;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import simpleGame.exception.OutOfBoardException;
public class StringColoringTest {
@Test //Structurel
public void colorStringTest() {
String purple = StringColoring.colorString('#', StringColoring.Color.PURPLE);
assertEquals(StringColoring.colorString('#',StringColoring.Color.PURPLE ), purple);
String cyan = StringColoring.colorString('#', StringColoring.Color.CYAN);
assertEquals(StringColoring.colorString('#',StringColoring.Color.CYAN ), cyan);
String red = StringColoring.colorString('#', StringColoring.Color.RED);
assertEquals(StringColoring.colorString('#',StringColoring.Color.RED ), red);
String white = StringColoring.colorString('#', StringColoring.Color.WHITE);
assertEquals(StringColoring.colorString('#',StringColoring.Color.WHITE ), white);
assertNotEquals("", white);
String d = StringColoring.colorString('#', StringColoring.Color.valueOf("DEFAULT"));
assertEquals(StringColoring.colorString('#',StringColoring.Color.DEFAULT ), d);
String black = StringColoring.colorString('#', StringColoring.Color.valueOf("BLACK"));
assertEquals(StringColoring.colorString('#',StringColoring.Color.BLACK ), black);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<javadocOptions>
<docletArtifacts>
<docletArtifact />
</docletArtifacts>
<tagletArtifacts>
<tagletArtifact />
</tagletArtifacts>
<links>
<link>../apidocs</link>
</links>
<javadocResourcesDirectory>src/test/javadoc</javadocResourcesDirectory>
</javadocOptions>
java.applet
java.awt
java.awt.color
java.awt.datatransfer