From 73481e1b22db09cfad9460b9b561889b4220fb67 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 17:04:45 +0200 Subject: [PATCH] Tests sur plateau, estboncodefalse --- Sources/UnitTesting/PlateauUT.cs | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/Sources/UnitTesting/PlateauUT.cs b/Sources/UnitTesting/PlateauUT.cs index c2a9736..0e69ba8 100644 --- a/Sources/UnitTesting/PlateauUT.cs +++ b/Sources/UnitTesting/PlateauUT.cs @@ -133,26 +133,40 @@ namespace UnitTesting [Fact] public void TestEstBonCodeFalse() { - List couleurs = new List((Couleur[])Enum.GetValues(typeof(Couleur))); - - Plateau plateau = new Plateau(4, 10); + Plateau plateau = new Plateau(2, 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(); - Couleur couleurJeton = jetons[0].Couleur; - int indice = couleurs.IndexOf(couleurJeton) + 1; - if (indice >= couleurs.Count) - indice = 0; + int i = 0; + int j = 1; + + 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);