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

130 lines
4.0 KiB

using CoreLibrary;
using System.Linq;
using Xunit;
namespace UnitTesting
{
public class PlateauUT
{
[Fact]
public void TestConstructorValid()
{
Plateau plateau = new Plateau(4,12);
Assert.NotNull(plateau);
Assert.Equal(1, plateau.Tour);
Assert.False(plateau.Victoire);
}
[Fact]
public void TestConstructorInvalid()
{
Assert.Throws<PlateauTailleCodeException>(() => new Plateau(0, 10));
}
[Fact]
public void TestEstCompletTrue()
{
Plateau plateau = new Plateau(4, 3);
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC), new Jeton(Couleur.JAUNE)]);
plateau.AjouterCode(code);
plateau.AjouterCode(code);
plateau.AjouterCode(code);
bool estComplet = plateau.EstComplet();
Assert.True(estComplet);
}
[Fact]
public void TestEstCompletFalse()
{
Plateau plateau = new Plateau(4, 3);
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC), new Jeton(Couleur.JAUNE)]);
plateau.AjouterCode(code);
plateau.AjouterCode(code);
bool estComplet = plateau.EstComplet();
Assert.False(estComplet);
}
[Fact]
public void TestAjouterCodeValid()
{
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);
Assert.Equal(2, plateau.Tour);
}
[Fact]
public void TestAjouterCodeIncorrectSize()
{
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)]);
Assert.Throws<PlateauTailleCodeException>(() => plateau.AjouterCode(code));
}
[Fact]
public void TestAjouterCodeIncomplete()
{
Plateau plateau = new Plateau(4, 10);
Code code = new Code(4);
Assert.Throws<PlateauCodeIncompletException>(() => plateau.AjouterCode(code));
}
[Fact]
public void TestEstBonCodeTrue()
{
}
[Fact]
public void TestEstBonCodeFalse()
{
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);
Assert.False(plateau.EstBonCode(code));
}
[Fact]
public void TestGrilleValid()
{
Plateau plateau = new Plateau(4, 3);
Code code1 = new Code([new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC), new Jeton(Couleur.JAUNE), new Jeton(Couleur.BLANC)]);
Code code2 = new Code([new Jeton(Couleur.VERT), new Jeton(Couleur.JAUNE), new Jeton(Couleur.ROUGE), new Jeton(Couleur.NOIR)]);
plateau.AjouterCode(code1);
plateau.AjouterCode(code2);
IEnumerable<IEnumerable<Jeton?>> grille = plateau.Grille();
Assert.Equal(4, grille.First().Count());
Assert.Equal(4, grille.Last().Count());
Assert.Equal(code1.Jetons(), grille.ElementAt(0));
Assert.Equal(code2.Jetons(), grille.ElementAt(1));
}
[Fact]
public void TestGrilleEmpty()
{
Plateau plateau = new Plateau(4, 3);
IEnumerable<IEnumerable<Jeton?>> grille = plateau.Grille();
foreach (IEnumerable<Jeton?> tour in grille)
{
Assert.All(tour, jeton => Assert.Null(jeton));
}
}
}
}