Tests Code et Plateau
continuous-integration/drone/push Build is passing Details

master
Pauline PRADY 12 months ago
parent 3dc8dada39
commit 3b72d209de

@ -88,6 +88,13 @@ namespace UnitTesting
Assert.Throws<IndiceCodeException>(() => code.RecupererJeton(4));
}
[Fact]
public void TestRecupererJetonNull()
{
Code code = new Code(4);
Assert.Throws<IndiceCodeException>(() => code.RecupererJeton(1));
}
[Fact]
public void TestJetonsValid()
{
@ -170,6 +177,19 @@ namespace UnitTesting
Assert.DoesNotContain(Indicateur.BONNEPLACE, indicateurs);
}
[Fact]
public void TestComparerBonnePlace()
{
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
Code autreCode = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.NOIR)]);
IEnumerable<Indicateur> indicateurs = code.Comparer(autreCode);
Assert.Equal(2, indicateurs.Count());
Assert.DoesNotContain(Indicateur.BONNECOULEUR, indicateurs);
Assert.Contains(Indicateur.BONNEPLACE, indicateurs);
}
[Fact]
public void TestComparerGoodPlaceAndColor()
{
@ -192,6 +212,17 @@ namespace UnitTesting
Assert.Empty(indicateurs);
}
[Fact]
public void TestComparerCodeIncomplet()
{
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
Code autreCode = new Code(3);
IEnumerable<Indicateur> indicateurs = code.Comparer(autreCode);
Assert.Empty(indicateurs);
}
}
}

@ -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);

Loading…
Cancel
Save