You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastermind/Sources/UnitTesting/PlateauUT.cs

101 lines
3.1 KiB

using CoreLibrary.Exceptions;
using System.Reflection;
using CoreLibrary.Core;
using Xunit;
namespace UnitTesting
{
public class PlateauUT
{
[Fact]
public void TestConstructeurValide()
{
Plateau plateau = new Plateau(4,12);
Assert.NotNull(plateau);
Assert.False(plateau.Victoire);
}
[Fact]
public void TestConstructeurInvalide()
{
Assert.Throws<TailleCodeException>(() => new Plateau(0, 10));
Assert.Throws<TailleGrilleException>(() => new Plateau(3, 0));
}
[Fact]
public void TestEstCompletTrue()
{
Plateau plateau = new Plateau(4, 3);
Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune)];
Code code = new Code(4);
code.AjouterJeton(jetons[0]);
code.AjouterJeton(jetons[1]);
code.AjouterJeton(jetons[2]);
plateau.AjouterCode(code);
plateau.AjouterCode(code);
plateau.AjouterCode(code);
bool estComplet = plateau.Complet;
Assert.True(estComplet);
}
[Fact]
public void TestEstCompletFalse()
{
Plateau plateau = new Plateau(4, 3);
Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune)];
Code code = new Code(4);
code.AjouterJeton(jetons[0]);
code.AjouterJeton(jetons[1]);
plateau.AjouterCode(code);
plateau.AjouterCode(code);
bool estComplet = plateau.Complet;
Assert.False(estComplet);
}
[Fact]
public void TestAjouterCodeTailleIncorrecte()
{
Plateau plateau = new Plateau(4, 10);
Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune), new Jeton(Couleur.Bleu)];
Code code = new Code(4);
code.AjouterJeton(jetons[0]);
code.AjouterJeton(jetons[1]);
code.AjouterJeton(jetons[2]);
code.AjouterJeton(jetons[3]);
code.AjouterJeton(jetons[4]);
Assert.Throws<CodeInvalideException>(() => plateau.AjouterCode(code));
}
[Fact]
public void TestAjouterCodeIncomplet()
{
Plateau plateau = new Plateau(4, 10);
Code code = new Code(4);
Assert.Throws<CodeIncompletException>(() => plateau.AjouterCode(code));
}
[Fact]
public void TestAjouterCodeBonCode()
{
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);
plateau.AjouterCode(codeSecret);
Assert.True(plateau.Victoire);
}
}
}