Test robot SupprimerCodesImpossibles
continuous-integration/drone/push Build is passing Details

master
Céleste BARBOSA 1 year ago
parent 191f1888ef
commit ad5e3ad6ed

@ -1,27 +1,40 @@
// Cas 3 - Plateau rempli, code mauvaise couleur using CoreLibrary.Core;
using CoreLibrary.Core; using CoreLibrary.Joueurs;
using System.Reflection; using System.Reflection;
Code code3 = new Code(1); Code codeSecret = new Code(1);
code3.AjouterJeton(new Jeton(Couleur.Rouge)); codeSecret.AjouterJeton(new Jeton(Couleur.Rouge));
Plateau plateau3; Code code1 = new Code(1);
Code? codeSecret3; code1.AjouterJeton(new Jeton(Couleur.Vert));
do
{
plateau3 = new Plateau(1, 1);
FieldInfo? codeSecretInfo3 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance); Code code2 = new Code(1);
code2.AjouterJeton(new Jeton(Couleur.Jaune));
codeSecret3 = codeSecretInfo3.GetValue(plateau2) as Code; List<Code> codes = new List<Code>([
Assert.NotNull(codeSecret3); codeSecret,
} while (codeSecret3.RecupererJeton(0).Equals(code3.RecupererJeton(0))); code1,
code2,
]);
plateau3.AjouterCode(codeSecret3); Plateau plateau = new Plateau(1, 1);
MethodInfo? EstCodePossible3 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); FieldInfo? codeSecretInfo = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(EstCodePossible3);
object? estPossibleObj3 = EstCodePossible3.Invoke(new Robot(), [plateau3, code3]); codeSecretInfo.SetValue(plateau, codeSecret);
Assert.NotNull(estPossibleObj3);
Assert.IsType<bool>(estPossibleObj3); codeSecretInfo = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.False((bool)estPossibleObj3);
plateau.AjouterCode(codeSecret);
var a = codeSecretInfo.GetValue(plateau);
var b = plateau.Grille;
MethodInfo? SupprimerCodesImpossiblesInfo = typeof(Robot).GetMethod("SupprimerCodesImpossibles", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
SupprimerCodesImpossiblesInfo.Invoke(new Robot(), [codes, plateau]);
Console.ReadLine();

@ -1,7 +1,4 @@
using System; using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit; using Xunit;
using CoreLibrary; using CoreLibrary;
using CoreLibrary.Core; using CoreLibrary.Core;
@ -9,8 +6,6 @@ using CoreLibrary.Joueurs;
using CoreLibrary.Regles; using CoreLibrary.Regles;
using CoreLibrary.Evenements; using CoreLibrary.Evenements;
using CoreLibrary.Exceptions; using CoreLibrary.Exceptions;
using System.Diagnostics.Tracing;
using Xunit.Abstractions;
namespace UnitTesting namespace UnitTesting

@ -1,6 +1,4 @@
using CoreLibrary; using CoreLibrary.Core;
using CoreLibrary.Core;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs; using CoreLibrary.Joueurs;
using System.Reflection; using System.Reflection;
using Xunit; using Xunit;
@ -69,5 +67,40 @@ namespace UnitTesting
Assert.IsType<bool>(estPossibleObj3); Assert.IsType<bool>(estPossibleObj3);
Assert.False((bool)estPossibleObj3); Assert.False((bool)estPossibleObj3);
} }
[Fact]
public void TestSupprimerCodesImpossibles()
{
Code codeSecret = new Code(1);
codeSecret.AjouterJeton(new Jeton(Couleur.Rouge));
Code code1 = new Code(1);
code1.AjouterJeton(new Jeton(Couleur.Vert));
Code code2 = new Code(1);
code2.AjouterJeton(new Jeton(Couleur.Jaune));
List<Code> codes = new List<Code>([
codeSecret,
code1,
code2,
]);
Plateau plateau = new Plateau(1, 1);
FieldInfo? codeSecretInfo = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(codeSecretInfo);
codeSecretInfo.SetValue(plateau, codeSecret);
plateau.AjouterCode(codeSecret);
Assert.Equal(3, codes.Count);
MethodInfo? SupprimerCodesImpossiblesInfo = typeof(Robot).GetMethod("SupprimerCodesImpossibles", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.NotNull(SupprimerCodesImpossiblesInfo);
SupprimerCodesImpossiblesInfo.Invoke(new Robot(), [codes, plateau]);
Assert.Single(codes);
}
} }
} }

Loading…
Cancel
Save