Merge branch 'UT' of https://codefirst.iut.uca.fr/git/nicolas.barbosa/mastermind into UT
continuous-integration/drone/push Build is passing Details

master
Pauline PRADY 11 months ago
commit 24e1182d66

@ -133,26 +133,40 @@ namespace UnitTesting
[Fact] [Fact]
public void TestEstBonCodeFalse() public void TestEstBonCodeFalse()
{ {
List<Couleur> couleurs = new List<Couleur>((Couleur[])Enum.GetValues(typeof(Couleur))); Plateau plateau = new Plateau(2, 10);
Plateau plateau = new Plateau(4, 10);
Type type = typeof(Plateau); Type type = typeof(Plateau);
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo); Assert.NotNull(fieldInfo);
Code? codeSecret = (Code?)fieldInfo.GetValue(plateau); Code? codeSecret = (Code?)fieldInfo.GetValue(plateau);
Assert.NotNull(codeSecret); Assert.NotNull(codeSecret);
Jeton[] jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray(); Jeton[] jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray();
Couleur couleurJeton = jetons[0].Couleur; int i = 0;
int indice = couleurs.IndexOf(couleurJeton) + 1; int j = 1;
if (indice >= couleurs.Count)
indice = 0; while (jetons[i].Couleur == jetons[j].Couleur)
{
++i;
++j;
if (j == jetons.Length)
{
plateau = new Plateau(2, 10);
codeSecret = (Code?)fieldInfo.GetValue(plateau);
Assert.NotNull(codeSecret);
jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray();
i = 0;
j = 1;
}
}
jetons[0] = new Jeton(couleurs[indice]); Jeton tmp = jetons[0];
jetons[0] = jetons[1];
jetons[1] = tmp;
Code code = new Code(jetons); Code code = new Code(jetons);

Loading…
Cancel
Save