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.
150 lines
4.9 KiB
150 lines
4.9 KiB
using CoreLibrary;
|
|
using CoreLibrary.Core;
|
|
using CoreLibrary.Exceptions;
|
|
using CoreLibrary.Joueurs;
|
|
using CoreLibrary.Regles;
|
|
using System.Reflection;
|
|
using Xunit;
|
|
|
|
namespace UnitTesting
|
|
{
|
|
public class ReglesClassiquesUT
|
|
{
|
|
[Fact]
|
|
public void TestNom()
|
|
{
|
|
Assert.Equal("Règles classiques", new ReglesClassiques().Nom);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestJoueurCourantPartieNonCommencee()
|
|
{
|
|
ReglesClassiques regles = new ReglesClassiques();
|
|
Assert.Throws<PartieNonCommenceeException>(() => regles.JoueurCourant());
|
|
}
|
|
|
|
[Fact]
|
|
public void TestPasserLaMainPartieNonCommencee()
|
|
{
|
|
ReglesClassiques regles = new ReglesClassiques();
|
|
Assert.Throws<PartieNonCommenceeException>(() => regles.PasserLaMain());
|
|
}
|
|
|
|
[Fact]
|
|
public void TestPasserLaMain()
|
|
{
|
|
ReglesClassiques regles = new ReglesClassiques();
|
|
|
|
Type type = typeof(ReglesClassiques);
|
|
|
|
FieldInfo? fieldInfo = type.GetField("joueurCourant", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
Assert.NotNull(fieldInfo);
|
|
|
|
|
|
regles.AjouterJoueur("céleste");
|
|
regles.AjouterJoueur("pauline");
|
|
|
|
Assert.Throws<PartieNonCommenceeException>(() => regles.PasserLaMain());
|
|
|
|
int? joueurCourantPasDemarree = (int?)fieldInfo.GetValue(regles);
|
|
Assert.Null(joueurCourantPasDemarree);
|
|
|
|
regles.CommencerLaPartie();
|
|
|
|
int? joueurCourantAvant = (int?) fieldInfo.GetValue(regles);
|
|
Joueur courantAvant = regles.JoueurCourant().Item1;
|
|
Assert.NotNull(joueurCourantAvant);
|
|
Assert.Equal(0, joueurCourantAvant);
|
|
|
|
regles.PasserLaMain();
|
|
|
|
int? joueurCourantApres = (int?)fieldInfo.GetValue(regles);
|
|
Joueur courantApres = regles.JoueurCourant().Item1;
|
|
Assert.NotNull(joueurCourantApres);
|
|
Assert.Equal(1, joueurCourantApres);
|
|
Assert.NotEqual(joueurCourantAvant, joueurCourantApres);
|
|
Assert.NotEqual(courantAvant, courantApres);
|
|
|
|
regles.PasserLaMain();
|
|
|
|
int? joueurCourantBoucle = (int?)fieldInfo.GetValue(regles);
|
|
Joueur courantBoucle = regles.JoueurCourant().Item1;
|
|
Assert.NotNull(joueurCourantBoucle);
|
|
Assert.Equal(0, joueurCourantBoucle);
|
|
Assert.NotEqual(joueurCourantApres, joueurCourantBoucle);
|
|
Assert.Equal(joueurCourantAvant, joueurCourantBoucle);
|
|
Assert.NotEqual(courantApres, courantBoucle);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestEstTermineeVictoire()
|
|
{
|
|
ReglesClassiques regles = new ReglesClassiques();
|
|
|
|
regles.AjouterJoueur("joueur1");
|
|
regles.AjouterJoueur("joueur2");
|
|
|
|
Assert.False(regles.EstTerminee());
|
|
|
|
Type type = typeof(ReglesClassiques);
|
|
FieldInfo? fieldInfo = type.GetField("joueurCourant", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
Assert.NotNull(fieldInfo);
|
|
fieldInfo.SetValue(regles, 1);
|
|
|
|
Assert.False(regles.EstTerminee());
|
|
|
|
fieldInfo.SetValue(regles, 0);
|
|
|
|
regles.CommencerLaPartie();
|
|
|
|
regles.PasserLaMain();
|
|
|
|
Assert.False(regles.EstTerminee());
|
|
|
|
regles.PasserLaMain();
|
|
|
|
Plateau plateauj1 = regles.JoueurCourant().Item2;
|
|
type = typeof(Plateau);
|
|
|
|
fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
Assert.NotNull(fieldInfo);
|
|
|
|
Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1);
|
|
Assert.NotNull(codeSecret);
|
|
|
|
regles.JoueurCourant().Item2.AjouterCode(codeSecret);
|
|
|
|
bool estTerminee = regles.EstTerminee();
|
|
|
|
Assert.True(estTerminee);
|
|
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public void TestGagants()
|
|
{
|
|
ReglesClassiques regles = new ReglesClassiques();
|
|
Partie partie = new Partie(regles);
|
|
|
|
regles.AjouterJoueur("joueur1");
|
|
regles.AjouterJoueur("joueur2");
|
|
|
|
regles.CommencerLaPartie();
|
|
|
|
Plateau plateauj1 = regles.JoueurCourant().Item2;
|
|
|
|
Type type = typeof(Plateau);
|
|
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
Assert.NotNull(fieldInfo);
|
|
Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1);
|
|
Assert.NotNull(codeSecret);
|
|
|
|
regles.JoueurCourant().Item2.AjouterCode(codeSecret);
|
|
IEnumerable<Joueur> gagnants = regles.Gagnants();
|
|
Assert.Single(gagnants);
|
|
Assert.Contains(regles.JoueurCourant().Item1, gagnants);
|
|
}
|
|
}
|
|
}
|