Commit 55ed2dfb authored by Aroubate Hamza's avatar Aroubate Hamza
Browse files

Testvivant; testpieddebiche TP4

parent df269c13
package fr.insarouen.asi.prog.asiaventure.elements.objets;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.junit.runner.RunWith;
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestPiedDeBiche.class
})
public class AllTestObjets{}
\ No newline at end of file
package fr.insarouen.asi.prog.asiaventure.elements.objets;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import fr.insarouen.asi.prog.asiaventure.Monde;
import fr.insarouen.asi.prog.asiaventure.elements.objets.PiedDeBiche;
import fr.insarouen.asi.prog.asiaventure.NomDEntiteDejaUtiliseDansLeMondeException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
public class TestPiedDeBiche {
private Monde m;
private PiedDeBiche pdb;
@Before
public void avantTest() throws NomDEntiteDejaUtiliseDansLeMondeException {
m = new Monde("m");
pdb = new PiedDeBiche("pdb", m);
}
@Test
public void test_estDeplacable() {
assertThat(pdb.estDeplacable(), IsEqual.equalTo(true));
}
}
\ No newline at end of file
......@@ -9,4 +9,4 @@ import org.junit.runners.Suite.SuiteClasses;
TestVivant.class
})
public class AllTestVivant{}
\ No newline at end of file
public class AllTestVivants{}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import org.junit.Test;
import fr.insarouen.asi.prog.asiaventure.Monde;
import fr.insarouen.asi.prog.asiaventure.NomDEntiteDejaUtiliseDansLeMondeException;
import fr.insarouen.asi.prog.asiaventure.elements.objets.Objet;
import fr.insarouen.asi.prog.asiaventure.elements.objets.PiedDeBiche;
import fr.insarouen.asi.prog.asiaventure.elements.objets.ObjetNonDeplacableException;
import fr.insarouen.asi.prog.asiaventure.elements.structure.ObjetAbsentDeLaPieceException;
import fr.insarouen.asi.prog.asiaventure.elements.structure.Piece;
......@@ -19,6 +20,9 @@ import static org.junit.Assert.*;
public class TestVivant {
public Monde monde;
public Piece piece;
private Vivant vivant;
private PiedDeBiche pieddebiche;
private PiedDeBiche pieddebiche1;
public class ObjetTest extends Objet {
boolean deplacable;
......@@ -36,9 +40,120 @@ public class TestVivant {
@Before
public void init() throws Exception{
monde = new Monde("un monde");
piece = new Piece("une piece", monde);
monde = new Monde("monde");
piece = new Piece(monde, "piece");
pieddebiche = new PiedDeBiche("pieddebiche", monde);
pieddebiche1 = new PiedDeBiche("pieddebiche1", monde);
vivant = new Vivant("vivant", monde, 10, 10, piece, pieddebiche, pieddebiche1){};
}
@Test()
public void test_Vivant() {
assertThat(vivant.getNom(), IsEqual.equalTo("vivant"));
assertThat(vivant.getMonde().getNom(), IsEqual.equalTo("monde"));
//assertThat(vivant.getPiece(), IsEqual.equalTo("piece"));
//assertThat(vivant.getPiece().contientVivant(vivant), IsEqual.equalTo(true));
}
@Test
public void test_getPointVie() {
assertThat(vivant.getPointVie(), IsEqual.equalTo(10));
}
@Test
public void test_getPointForce() {
assertThat(vivant.getPointForce(), IsEqual.equalTo(10));
}
@Test
public void test_getObjet() {
assertThat(vivant.getObjet("pieddebiche"), IsEqual.equalTo(pieddebiche));
assertThat(vivant.getObjet("pieddebiche_null"), IsEqual.equalTo(null));
}
@Test
public void test_getObjets() {
Objet[] objets = new Objet[2];
objets[0] = pieddebiche;
objets[1] = pieddebiche1;
assertThat(vivant.getObjets().length, IsEqual.equalTo(2));
assertThat(vivant.getObjets(), IsEqual.equalTo(objets));
}
@Test
public void test_getPiece() {
assertThat(vivant.getPiece().getNom(), IsEqual.equalTo("piece"));
}
@Test
public void test_possede() throws NomDEntiteDejaUtiliseDansLeMondeException {
assertThat(vivant.possede(pieddebiche), IsEqual.equalTo(true));
assertThat(vivant.possede(pieddebiche1), IsEqual.equalTo(true));
ObjetTest obj = new ObjetTest("obj", monde, true);
assertThat(vivant.possede(obj), IsEqual.equalTo(false));
}
@Test
public void test_prendre() throws ObjetAbsentDeLaPieceException,
ObjetNonDeplacableException, NomDEntiteDejaUtiliseDansLeMondeException {
ObjetTest obj1 = new ObjetTest("obj1", monde, true);
Objet[] objets = new Objet[3];
objets[0] = pieddebiche;
objets[1] = pieddebiche1;
objets[2] = obj1;
piece.deposer(obj1);
vivant.prendre(obj1);
assertThat(vivant.getObjets(), IsEqual.equalTo(objets));
}
@Test(expected = ObjetAbsentDeLaPieceException.class)
public void ExceptionTest() throws ObjetAbsentDeLaPieceException,
ObjetNonDeplacableException, NomDEntiteDejaUtiliseDansLeMondeException {
ObjetTest obj = new ObjetTest("obj", monde, true);
vivant.prendre(obj);
}
@Test(expected = ObjetNonDeplacableException.class)
public void ExceptionTest1() throws ObjetAbsentDeLaPieceException,
ObjetNonDeplacableException, NomDEntiteDejaUtiliseDansLeMondeException {
ObjetTest obj = new ObjetTest("obj", monde, false);
piece.deposer(obj);
vivant.prendre(obj);
}
@Test
public void test_deposer() throws ObjetNonPossedeParLeVivantException {
Objet[] objets = new Objet[1];
objets[0] = pieddebiche;
vivant.deposer(pieddebiche1);
assertThat(vivant.getObjets().length, IsEqual.equalTo(1));
assertThat(vivant.getObjets(), IsEqual.equalTo(objets));
}
@Test(expected = ObjetNonPossedeParLeVivantException.class)
public void ExceptionTest2() throws ObjetNonPossedeParLeVivantException,
NomDEntiteDejaUtiliseDansLeMondeException {
ObjetTest obj = new ObjetTest("obj", monde, false);
vivant.deposer(obj);
}
}
\ No newline at end of file
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