ConditionTests 100% Coverage
This commit is contained in:
@ -4,7 +4,5 @@ import main.Joueur;
|
||||
|
||||
public abstract class Condition {
|
||||
|
||||
public boolean isTrue(Joueur joueur) {
|
||||
return true;
|
||||
}
|
||||
public abstract boolean isTrue(Joueur joueur);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package condition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import main.Joueur;
|
||||
@ -10,16 +9,17 @@ public class ConditionMultiple extends Condition {
|
||||
|
||||
private List<Condition> conditions;
|
||||
|
||||
public ConditionMultiple(Condition ...conditions) {
|
||||
public ConditionMultiple(List<Condition> conditions) {
|
||||
|
||||
this.conditions = new ArrayList<Condition>();
|
||||
this.conditions.addAll(Arrays.asList(conditions));
|
||||
this.conditions.addAll(conditions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie que toutes les conditions soient vraies
|
||||
* @param joueur Le joueur sur lequel on vérifie les conditions.
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public boolean isTrue(Joueur joueur)
|
||||
@ -35,10 +35,5 @@ public class ConditionMultiple extends Condition {
|
||||
public List<Condition> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void setConditions(List<Condition> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package condition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import main.Joueur;
|
||||
|
||||
public class ConditionMultipleOR extends ConditionMultiple{
|
||||
|
||||
|
||||
public ConditionMultipleOR(Condition ...conditions) {
|
||||
public ConditionMultipleOR(List<Condition> conditions) {
|
||||
super(conditions);
|
||||
}
|
||||
|
||||
@ -13,6 +15,7 @@ public class ConditionMultipleOR extends ConditionMultiple{
|
||||
* Vérifie qu'au moins une des conditions soit vérifiée.
|
||||
* @param joueur Le joueur sur lequel on vérifie les conditions.
|
||||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public boolean isTrue(Joueur joueur)
|
||||
|
@ -26,9 +26,7 @@ public class ConditionStatistiques extends Condition {
|
||||
*/
|
||||
public ConditionStatistiques(boolean plateauJoueur,String key,int value,int equalMoreLess) {
|
||||
|
||||
if(equalMoreLess >= 0 && equalMoreLess <= 2) this.equalMoreLess = equalMoreLess;
|
||||
else {} // TODO exception
|
||||
|
||||
this.equalMoreLess = equalMoreLess;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.plateauJoueur = plateauJoueur;
|
||||
@ -36,10 +34,11 @@ public class ConditionStatistiques extends Condition {
|
||||
|
||||
/**
|
||||
* @param joueur sur lequel on vérifie la condition
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public boolean isTrue(Joueur joueur) {
|
||||
public boolean isTrue(Joueur joueur){
|
||||
|
||||
int valeur;
|
||||
if(this.plateauJoueur)
|
||||
@ -55,11 +54,11 @@ public class ConditionStatistiques extends Condition {
|
||||
case EQUAL:
|
||||
return this.value == valeur;
|
||||
case MORE:
|
||||
return this.value >= valeur;
|
||||
case LESS:
|
||||
return this.value <= valeur;
|
||||
case LESS:
|
||||
return this.value >= valeur;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class WinConditionHunter extends Condition{
|
||||
int nbShadow = j.getPlateau().getStat(Plateau.NB_SHADOWS);
|
||||
|
||||
Condition winCondition = new ConditionStatistiques(
|
||||
ConditionStatistiques.PLATEAU, Plateau.NB_MORTS_SHADOW, nbShadow, ConditionStatistiques.LESS);
|
||||
ConditionStatistiques.PLATEAU, Plateau.NB_MORTS_SHADOW, nbShadow, ConditionStatistiques.MORE);
|
||||
return winCondition.isTrue(j);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
package condition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import main.Joueur;
|
||||
import main.Plateau;
|
||||
|
||||
@ -9,10 +12,15 @@ public class WinConditionShadow extends Condition{
|
||||
public boolean isTrue(Joueur j)
|
||||
{
|
||||
int nbHunter = j.getPlateau().getStat(Plateau.NB_HUNTERS);
|
||||
|
||||
List<Condition> conditions = new ArrayList<Condition>();
|
||||
|
||||
conditions.add(new ConditionStatistiques(ConditionStatistiques.PLATEAU,Plateau.NB_MORTS_NEUTRAL,3,ConditionStatistiques.MORE));
|
||||
conditions.add(new ConditionStatistiques(ConditionStatistiques.PLATEAU, Plateau.NB_MORTS_HUNTER, nbHunter, ConditionStatistiques.MORE));
|
||||
|
||||
|
||||
Condition winCondition =
|
||||
new ConditionMultipleOR(
|
||||
new ConditionStatistiques(ConditionStatistiques.PLATEAU,Plateau.NB_MORTS_NEUTRAL,3,ConditionStatistiques.LESS),
|
||||
new ConditionStatistiques(ConditionStatistiques.PLATEAU, Plateau.NB_MORTS_HUNTER, nbHunter, ConditionStatistiques.LESS));
|
||||
new ConditionMultipleOR(conditions);
|
||||
return winCondition.isTrue(j);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user