|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
using CoreLibrary;
|
|
|
|
|
using CoreLibrary.Exceptions;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace UnitTesting
|
|
|
|
@ -20,6 +20,7 @@ namespace UnitTesting
|
|
|
|
|
public void TestConstructorInvalid()
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<TailleCodeException>(() => new Plateau(0, 10));
|
|
|
|
|
Assert.Throws<TailleGrilleException>(() => new Plateau(3, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
@ -50,7 +51,7 @@ namespace UnitTesting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestAjouterCodeValid()
|
|
|
|
|
public void TestAjouterCodeValide()
|
|
|
|
|
{
|
|
|
|
|
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)]);
|
|
|
|
@ -61,7 +62,7 @@ namespace UnitTesting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestAjouterCodeIncorrectSize()
|
|
|
|
|
public void TestAjouterCodeTailleIncorrecte()
|
|
|
|
|
{
|
|
|
|
|
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), new Jeton(Couleur.JAUNE)]);
|
|
|
|
@ -70,7 +71,7 @@ namespace UnitTesting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestAjouterCodeIncomplete()
|
|
|
|
|
public void TestAjouterCodeIncomplet()
|
|
|
|
|
{
|
|
|
|
|
Plateau plateau = new Plateau(4, 10);
|
|
|
|
|
Code code = new Code(4);
|
|
|
|
@ -79,14 +80,61 @@ namespace UnitTesting
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeTrue()
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeTailleException()
|
|
|
|
|
{
|
|
|
|
|
Plateau plateau = new Plateau(3, 5);
|
|
|
|
|
Code code = new Code(4);
|
|
|
|
|
|
|
|
|
|
Assert.Throws<CodeInvalideException>(() => plateau.EstBonCode(code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeIncomplet()
|
|
|
|
|
{
|
|
|
|
|
Plateau plateau = new Plateau(3, 5);
|
|
|
|
|
Code code = new Code(3);
|
|
|
|
|
|
|
|
|
|
Assert.Throws<CodeIncompletException>(() => plateau.EstBonCode(code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeTrue()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
bool resultat = plateau.EstBonCode(codeSecret);
|
|
|
|
|
Assert.True(resultat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstBonCodeFalse()
|
|
|
|
|
{
|
|
|
|
|
// Modifier pour obtenir code différent de codeSecret
|
|
|
|
|
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);
|
|
|
|
|