Début tests unitaires code, jeton, joueur

master
Pauline PRADY 12 months ago
parent 68f31b4eb2
commit e0809011a8

@ -0,0 +1,81 @@
using CoreLibrary;
using Xunit;
namespace UnitTesting
{
public class CodeUT
{
[Fact]
public void TestFirstConstructorValidArguments()
{
Code code = new Code(4);
Assert.NotNull(code);
Assert.Equal(4, code.Jetons().Count());
Assert.Equal(0, code.NbJetons);
}
[Fact]
public void TestConstructorInvalidArguments()
{
Assert.Throws<ArgumentException>(() => new Code(0));
Assert.Throws<ArgumentException>(() => new Code(-1));
}
[Fact]
public void TestSecondConstructorValidArguments()
{
Jeton?[] jetons = [new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLEU)];
Code code = new Code(jetons);
Assert.NotNull(code);
Assert.Equal(3, code.Jetons().Count());
Assert.Equal(3, code.NbJetons);
}
[Fact]
public void TestSecondConstructorInvalidArguments()
{
Assert.Throws<ArgumentException>(() => new Code([]));
}
[Fact]
public void TestAjouterJetonValid()
{
Jeton jeton = new Jeton(Couleur.JAUNE);
Code code = new Code(3);
code.AjouterJeton(jeton);
Assert.Equal(1, code.NbJetons);
Assert.Equal(jeton, code.Jetons().ElementAt(0));
}
[Fact]
public void TestAjouterJetonInvalid()
{
Code code = new Code([new Jeton(Couleur.NOIR)]);
Assert.Throws<Exception>(() => code.AjouterJeton(new Jeton(Couleur.ROUGE)));
}
[Fact]
public void TestSupprimerDernierJetonValid()
{
Code code = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU), new Jeton(Couleur.BLANC)]);
code.SupprimerDernierJeton();
Assert.Equal(2, code.NbJetons);
}
[Fact]
public void TestSupprimerDernierJetonInvalid()
{
Code code = new Code([]);
Assert.Throws<Exception>(() => code.SupprimerDernierJeton());
Code code2 = new Code(4);
Assert.Throws<Exception>(() => code2.SupprimerDernierJeton());
}
[Fact]
public void TestRecupererJetonValid()
{
}
}
}

@ -0,0 +1,20 @@
using CoreLibrary;
using Xunit;
namespace UnitTesting
{
public class JetonUT
{
[Fact]
public void TestConstructorValid()
{
Couleur[] listeCouleurs = (Couleur[])Enum.GetValues(typeof(Couleur));
for (int i=0; i<listeCouleurs.Length; ++i)
{
Jeton jeton = new Jeton(listeCouleurs[i]);
Assert.Equal(listeCouleurs[i], jeton.Couleur);
}
}
}
}

@ -0,0 +1,13 @@
using CoreLibrary;
namespace UnitTesting
{
public class JoueurUT
{
//[Fact]
//public void TestConstructorWithValidArguments()
//{
// Joueur joueur = new Joueur("MonJoueur", plateau);
//}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@ -22,4 +22,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoreLibrary\CoreLibrary.csproj" />
</ItemGroup>
</Project>

Loading…
Cancel
Save