|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using CoreLibrary;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace UnitTesting
|
|
|
|
@ -66,16 +67,141 @@ namespace UnitTesting
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestSupprimerDernierJetonInvalid()
|
|
|
|
|
{
|
|
|
|
|
//Code code = new Code([]);
|
|
|
|
|
//Assert.Throws<CodeTableauLesJetonsVideException>(() => code.SupprimerDernierJeton());
|
|
|
|
|
Code code2 = new Code(4);
|
|
|
|
|
Assert.Throws<CodeTableauLesJetonsVideException>(() => code2.SupprimerDernierJeton());
|
|
|
|
|
Code code = new Code(4);
|
|
|
|
|
Assert.Throws<CodeTableauLesJetonsVideException>(() => code.SupprimerDernierJeton());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestRecupererJetonValid()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
Jeton jetonAttendu = new Jeton(Couleur.BLEU);
|
|
|
|
|
Jeton jeton = code.RecupererJeton(1);
|
|
|
|
|
Assert.Equal(jetonAttendu.Couleur, jeton.Couleur);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestRecupererJetonInvalid()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code(4);
|
|
|
|
|
Assert.Throws<CodeIndiceHorsDePorteeException>(() => code.RecupererJeton(-1));
|
|
|
|
|
Assert.Throws<CodeIndiceHorsDePorteeException>(() => code.RecupererJeton(5));
|
|
|
|
|
Assert.Throws<CodeJetonNullException>(() => code.RecupererJeton(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestJetonsValid()
|
|
|
|
|
{
|
|
|
|
|
Jeton[] jetonsAttendus = [new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLEU)];
|
|
|
|
|
Code code = new Code(jetonsAttendus);
|
|
|
|
|
IEnumerable<Jeton?> lesJetons = code.Jetons();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(jetonsAttendus.Length, lesJetons.Count());
|
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
foreach (Jeton jetonAttendu in jetonsAttendus)
|
|
|
|
|
{
|
|
|
|
|
Assert.Equal(jetonAttendu.Couleur, lesJetons.ElementAt(index)?.Couleur);
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstCompletValid()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
bool estComplet = code.EstComplet();
|
|
|
|
|
Assert.True(estComplet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEstCompletInvalid()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code(3);
|
|
|
|
|
bool estComplet = code.EstComplet();
|
|
|
|
|
Assert.False(estComplet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestTailleMaximaleValid()
|
|
|
|
|
{
|
|
|
|
|
Jeton[] jetons = [new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLEU)];
|
|
|
|
|
Code code = new Code(jetons);
|
|
|
|
|
int tailleMaximale = code.TailleMaximale();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(jetons.Length, tailleMaximale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestComparerValid()
|
|
|
|
|
{
|
|
|
|
|
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.BLANC)]);
|
|
|
|
|
|
|
|
|
|
IEnumerable<Indicateur> indicateurs = code.Comparer(autreCode);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(3, indicateurs.Count());
|
|
|
|
|
Assert.Contains(Indicateur.BONNEPLACE, indicateurs);
|
|
|
|
|
Assert.DoesNotContain(Indicateur.BONNECOULEUR, indicateurs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestComparerGoodPlace()
|
|
|
|
|
{
|
|
|
|
|
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.Contains(Indicateur.BONNEPLACE, indicateurs);
|
|
|
|
|
Assert.DoesNotContain(Indicateur.BONNECOULEUR, indicateurs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestComparerGoodColor()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
Code autreCode = new Code([new Jeton(Couleur.BLEU), new Jeton(Couleur.ROUGE), new Jeton(Couleur.NOIR)]);
|
|
|
|
|
|
|
|
|
|
IEnumerable<Indicateur> indicateurs = code.Comparer(autreCode);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, indicateurs.Count());
|
|
|
|
|
Assert.Contains(Indicateur.BONNECOULEUR, indicateurs);
|
|
|
|
|
Assert.DoesNotContain(Indicateur.BONNEPLACE, indicateurs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestComparerGoodPlaceAndColor()
|
|
|
|
|
{
|
|
|
|
|
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.BLANC), new Jeton(Couleur.BLEU)]);
|
|
|
|
|
|
|
|
|
|
IEnumerable<Indicateur> indicateurs = code.Comparer(autreCode);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(3, indicateurs.Count());
|
|
|
|
|
Assert.Contains(Indicateur.BONNEPLACE, indicateurs);
|
|
|
|
|
Assert.Contains(Indicateur.BONNECOULEUR, indicateurs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestComparerNoMatch()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
Code autreCode = new Code([new Jeton(Couleur.VERT), new Jeton(Couleur.JAUNE), new Jeton(Couleur.NOIR)]);
|
|
|
|
|
IEnumerable<Indicateur> indicateurs = code.Comparer(autreCode);
|
|
|
|
|
|
|
|
|
|
Assert.Empty(indicateurs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestComparerInvalid()
|
|
|
|
|
{
|
|
|
|
|
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
|
|
|
|
|
Code autreCode = new Code(3);
|
|
|
|
|
|
|
|
|
|
Assert.Throws<CodeTableauLesJetonsIncompletException>(() => code.Comparer(autreCode));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|