|
|
|
@ -127,21 +127,71 @@ namespace UnitTesting
|
|
|
|
|
Code? codeSecret = (Code?)fieldInfo.GetValue(plateau);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecret);
|
|
|
|
|
bool resultat = plateau.EstBonCode(codeSecret);
|
|
|
|
|
Assert.True(resultat);
|
|
|
|
|
Assert.True(plateau.EstBonCode(codeSecret));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeFalse()
|
|
|
|
|
{
|
|
|
|
|
// Modifier pour obtenir code différent de codeSecret
|
|
|
|
|
List<Couleur> couleurs = new List<Couleur>((Couleur[])Enum.GetValues(typeof(Couleur)));
|
|
|
|
|
|
|
|
|
|
Plateau plateau = new Plateau(4, 10);
|
|
|
|
|
Code code = new Code([new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC), new Jeton(Couleur.JAUNE), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
plateau.AjouterCode(code);
|
|
|
|
|
|
|
|
|
|
Type type = typeof(Plateau);
|
|
|
|
|
|
|
|
|
|
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
Assert.NotNull(fieldInfo);
|
|
|
|
|
|
|
|
|
|
Code? codeSecret = (Code?)fieldInfo.GetValue(plateau);
|
|
|
|
|
Assert.NotNull(codeSecret);
|
|
|
|
|
|
|
|
|
|
Jeton[] jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray();
|
|
|
|
|
|
|
|
|
|
Couleur couleurJeton = jetons[0].Couleur;
|
|
|
|
|
int indice = couleurs.IndexOf(couleurJeton) + 1;
|
|
|
|
|
if (indice >= couleurs.Count)
|
|
|
|
|
indice = 0;
|
|
|
|
|
|
|
|
|
|
jetons[0] = new Jeton(couleurs[indice]);
|
|
|
|
|
|
|
|
|
|
Code code = new Code(jetons);
|
|
|
|
|
|
|
|
|
|
Assert.False(plateau.EstBonCode(code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeAucunIndicateur()
|
|
|
|
|
{
|
|
|
|
|
List<Couleur> couleurs = new List<Couleur>((Couleur[])Enum.GetValues(typeof(Couleur)));
|
|
|
|
|
Plateau plateau = new Plateau(4, 10);
|
|
|
|
|
Type type = typeof(Plateau);
|
|
|
|
|
|
|
|
|
|
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
Assert.NotNull(fieldInfo);
|
|
|
|
|
|
|
|
|
|
Code? codeSecret = (Code?)fieldInfo.GetValue(plateau);
|
|
|
|
|
Assert.NotNull(codeSecret);
|
|
|
|
|
|
|
|
|
|
Jeton[] jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray();
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<jetons.Length; ++i)
|
|
|
|
|
{
|
|
|
|
|
Couleur couleurJeton = jetons[i].Couleur;
|
|
|
|
|
couleurs.Remove(couleurJeton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Code code = new Code(
|
|
|
|
|
[
|
|
|
|
|
new Jeton(couleurs[0]),
|
|
|
|
|
new Jeton(couleurs[0]),
|
|
|
|
|
new Jeton(couleurs[0]),
|
|
|
|
|
new Jeton(couleurs[0])
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Assert.False(plateau.EstBonCode(code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestGrilleValid()
|
|
|
|
|
{
|
|
|
|
@ -174,5 +224,32 @@ namespace UnitTesting
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestIndicateursVide()
|
|
|
|
|
{
|
|
|
|
|
Plateau plateau = new Plateau(4, 5);
|
|
|
|
|
|
|
|
|
|
foreach(Indicateur[] indicateur in plateau.Indicateurs())
|
|
|
|
|
{
|
|
|
|
|
Assert.Null(indicateur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestIndicateursAjouterDeuxCodes()
|
|
|
|
|
{
|
|
|
|
|
Plateau plateau = new Plateau(4, 5);
|
|
|
|
|
Code code1 = new Code([new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC), new Jeton(Couleur.JAUNE), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
Code code2 = new Code([new Jeton(Couleur.VERT), new Jeton(Couleur.JAUNE), new Jeton(Couleur.ROUGE), new Jeton(Couleur.NOIR)]);
|
|
|
|
|
|
|
|
|
|
plateau.AjouterCode(code1);
|
|
|
|
|
plateau.AjouterCode(code2);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(plateau.Indicateurs().ElementAt(0));
|
|
|
|
|
Assert.NotNull(plateau.Indicateurs().ElementAt(1));
|
|
|
|
|
Assert.Null(plateau.Indicateurs().ElementAt(2));
|
|
|
|
|
Assert.Null(plateau.Indicateurs().ElementAt(3));
|
|
|
|
|
Assert.Null(plateau.Indicateurs().ElementAt(4));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|