diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs index c7c5129..5f7a9dc 100644 --- a/Sources/ConsoleApp/Program.cs +++ b/Sources/ConsoleApp/Program.cs @@ -9,8 +9,8 @@ using Persistance.Persistance; namespace ConsoleApp { /// - /// Permet de jouer une partie de mastermind, avec les règles classiques - /// (2 joueurs, 12 tours, un code à 4 couleurs parmi 6) + /// Permet de jouer une partie de mastermind, avec les regles classiques + /// (2 joueurs, 12 tours, un code a code couleurs parmi 6) /// [ExcludeFromCodeCoverage] public static class Program diff --git a/Sources/UnitTesting/CodeUT.cs b/Sources/UnitTesting/CodeUT.cs index 0109ac8..3b44478 100644 --- a/Sources/UnitTesting/CodeUT.cs +++ b/Sources/UnitTesting/CodeUT.cs @@ -5,8 +5,14 @@ using Xunit; namespace UnitTesting { + /// + /// + /// public class CodeUT { + /// + /// + /// [Fact] public void TestPremierConstructeurValide() { @@ -18,12 +24,18 @@ namespace UnitTesting Assert.True(code.Vide); } + /// + /// + /// [Fact] public void TestPremierConstructeurInvalide() { Assert.Throws(() => new Code(-1)); } + /// + /// + /// [Fact] public void TestAjouterJetonValide() { @@ -34,6 +46,9 @@ namespace UnitTesting Assert.Equal(jeton, code.Jetons.ElementAt(0)); } + /// + /// + /// [Fact] public void TestAjouterJetonInvalide() { @@ -45,6 +60,9 @@ namespace UnitTesting Assert.Throws(() => code.AjouterJeton(new Jeton(Couleur.Rouge))); } + /// + /// + /// [Fact] public void TestSupprimerDernierJetonValide() { @@ -57,6 +75,9 @@ namespace UnitTesting Assert.Equal(2, code.Taille); } + /// + /// + /// [Fact] public void TestSupprimerDernierJetonInvalide() { @@ -64,6 +85,9 @@ namespace UnitTesting Assert.Throws(() => code.SupprimerDernierJeton()); } + /// + /// + /// [Fact] public void TestRecupererJetonValide() { @@ -77,6 +101,9 @@ namespace UnitTesting Assert.Equal(jetonAttendu.Couleur, jeton.Couleur); } + /// + /// + /// [Fact] public void TestRecupererJetonInvalide() { @@ -85,6 +112,9 @@ namespace UnitTesting Assert.Throws(() => code.RecupererJeton(4)); } + /// + /// + /// [Fact] public void TestRecupererJetonNull() { @@ -92,6 +122,9 @@ namespace UnitTesting Assert.Throws(() => code.RecupererJeton(1)); } + /// + /// + /// [Fact] public void TestJetonsValide() { @@ -112,6 +145,9 @@ namespace UnitTesting } } + /// + /// + /// [Fact] public void TestEstCompletValide() { @@ -124,6 +160,9 @@ namespace UnitTesting Assert.True(estComplet); } + /// + /// + /// [Fact] public void TestEstCompletInvalide() { @@ -132,6 +171,9 @@ namespace UnitTesting Assert.False(estComplet); } + /// + /// + /// [Fact] public void TestTailleMaximaleValide() { @@ -145,6 +187,9 @@ namespace UnitTesting Assert.Equal(jetons.Length, tailleMaximale); } + /// + /// + /// [Fact] public void TestComparerValide() { @@ -165,6 +210,9 @@ namespace UnitTesting Assert.Equal(3, indicateurs.Count); } + /// + /// + /// [Fact] public void TestComparerDifferent() { @@ -185,6 +233,9 @@ namespace UnitTesting Assert.Empty(indicateurs); } + /// + /// + /// [Fact] public void TestComparerMonCodeIncomplet() { @@ -201,6 +252,9 @@ namespace UnitTesting Assert.Empty(indicateurs); } + /// + /// + /// [Fact] public void TestComparerSonCodeIncomplet() { @@ -215,6 +269,9 @@ namespace UnitTesting Assert.Throws(() => code1.Comparer(code2)); } + /// + /// + /// [Fact] public void TestToString() { @@ -227,6 +284,9 @@ namespace UnitTesting Assert.Equal("Code(1)", code.ToString()); } + /// + /// + /// [Fact] public void TestComparerCodeInvalide() { @@ -239,6 +299,9 @@ namespace UnitTesting Assert.Throws(() => code.Comparer(code1)); } + /// + /// + /// [Fact] public void TestComparerCodeCorrect() { diff --git a/Sources/UnitTesting/JetonUT.cs b/Sources/UnitTesting/JetonUT.cs index f55fc8c..7fd6d03 100644 --- a/Sources/UnitTesting/JetonUT.cs +++ b/Sources/UnitTesting/JetonUT.cs @@ -3,8 +3,14 @@ using Xunit; namespace UnitTesting { + /// + /// + /// public class JetonUT - { + { + /// + /// + /// [Fact] public void TestConstructeurValide() { @@ -15,8 +21,11 @@ namespace UnitTesting Jeton jeton = new Jeton(listeCouleurs[i]); Assert.Equal(listeCouleurs[i], jeton.Couleur); } - } - + } + + /// + /// + /// [Fact] public void TestEquals() { diff --git a/Sources/UnitTesting/JoueurUT.cs b/Sources/UnitTesting/JoueurUT.cs index 29acddb..3cfdd81 100644 --- a/Sources/UnitTesting/JoueurUT.cs +++ b/Sources/UnitTesting/JoueurUT.cs @@ -9,8 +9,14 @@ using Xunit; namespace UnitTesting { + /// + /// + /// public class JoueurUT { + /// + /// + /// [Fact] public void TestConstructeur1Valide() { @@ -22,7 +28,9 @@ namespace UnitTesting Assert.Equal(nom, joueur.Nom); } - + /// + /// + /// [Fact] public void TestConstructeur2Valide() { @@ -34,6 +42,9 @@ namespace UnitTesting Assert.Equal(nom, joueur.Nom); } + /// + /// + /// [Fact] public void TestQuandJoueurSeConnecter() { @@ -56,6 +67,9 @@ namespace UnitTesting Assert.Equal(joueur2, eventArgs?.Joueur); } + /// + /// + /// [Fact] public void TestSeConnecterDeclencheEvenement() { @@ -77,6 +91,9 @@ namespace UnitTesting Assert.Equal(joueur2, eventArgs?.Joueur); } + /// + /// + /// [Fact] public void TestToStringValide() { @@ -86,6 +103,9 @@ namespace UnitTesting Assert.Equal(nom, result); } + /// + /// + /// [Fact] public void TestToStringVide() { @@ -95,6 +115,9 @@ namespace UnitTesting Assert.Equal("", result); } + /// + /// + /// [Fact] public void TestStatistiqueNonDefinie() { @@ -107,6 +130,9 @@ namespace UnitTesting Assert.Equal(0, result); } + /// + /// + /// [Fact] public void TestStatistiqueDefinie() { @@ -120,6 +146,9 @@ namespace UnitTesting Assert.Equal(1, result); } + /// + /// + /// [Fact] public void TestIncrementerStatistiqueUn() { @@ -133,6 +162,9 @@ namespace UnitTesting Assert.Equal(1, result); } + /// + /// + /// [Fact] public void TestIncrementerStatistiqueDeux() { diff --git a/Sources/UnitTesting/ManageurUT.cs b/Sources/UnitTesting/ManageurUT.cs index 0e6443d..a24e089 100644 --- a/Sources/UnitTesting/ManageurUT.cs +++ b/Sources/UnitTesting/ManageurUT.cs @@ -11,8 +11,14 @@ using Xunit; namespace UnitTesting { + /// + /// Classe test pour la classe Manageur. + /// public class ManageurUT - { + { + /// + /// Test le constructeur de Manageur. + /// [Fact] public void TestConstruteur() { @@ -27,8 +33,11 @@ namespace UnitTesting Assert.NotNull(manageur.PartiesNonTerminees); Assert.NotEmpty(manageur.Joueurs); - } - + } + + /// + /// Test la méthode Sauvegarder d'une partie. + /// [Fact] public void TestSauvegarder() { @@ -38,8 +47,11 @@ namespace UnitTesting MethodInfo? infosMethode = typeof(Manageur).GetMethod("Sauvegarder", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(infosMethode); infosMethode.Invoke(manageur, []); - } - + } + + /// + /// Test la méthode ChargerPartie qui charge une partie. + /// [Fact] public void TestChargerPartie() { @@ -55,8 +67,11 @@ namespace UnitTesting Assert.Contains(nouvellePartie, manageur.Parties); Assert.Contains(nouvellePartie, manageur.PartiesNonTerminees); - } - + } + + /// + /// Test la méthode NouvellePartie de Manageur. + /// [Fact] public void TestNouvellePartie() { @@ -67,8 +82,11 @@ namespace UnitTesting Assert.Contains(nouvellePartie, manageur.Parties); Assert.Contains(nouvellePartie, manageur.PartiesNonTerminees); - } - + } + + /// + /// Premier test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie() { @@ -154,8 +172,11 @@ namespace UnitTesting Assert.NotEmpty(PartieDemanderJoueurJouer.GetInvocationList()); Assert.NotEmpty(PartiePasserLaMain.GetInvocationList()); Assert.NotEmpty(PartiePartieTerminee.GetInvocationList()); - } - + } + + /// + /// Deuxième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie2() { @@ -203,8 +224,11 @@ namespace UnitTesting Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Troisième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie3() { @@ -252,8 +276,11 @@ namespace UnitTesting Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Quatrième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie4() { @@ -301,8 +328,11 @@ namespace UnitTesting Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Cinquième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie5() { @@ -350,8 +380,11 @@ namespace UnitTesting Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Test de la méthode DemanderJoueurExistant de Manageur. + /// [Fact] public void TestDemanderJoueurExistant() { @@ -367,8 +400,11 @@ namespace UnitTesting object? toto = infosMethode.Invoke(manageur, ["Toto"]); Assert.Null(toto); - } - + } + + /// + /// Test de la méthode DemanderJoueur de Manageur. + /// [Fact] public void TestDemanderJoueur() { diff --git a/Sources/UnitTesting/PartieUT.cs b/Sources/UnitTesting/PartieUT.cs index 1335f5d..1b57245 100644 --- a/Sources/UnitTesting/PartieUT.cs +++ b/Sources/UnitTesting/PartieUT.cs @@ -10,18 +10,26 @@ using CoreLibrary.Exceptions; namespace UnitTesting { + /// + /// Classe test pour la classe Partie. + /// public class PartieUT - { + { + /// + /// Test le premier constructeur de Partie valide. + /// [Fact] - public void TestPremierConstructeurValide() { IRegles regle = new ReglesClassiques(); Partie partie = new Partie(regle); Assert.Equal(regle, partie.Regles); - } - + } + + /// + /// Test le deuxième constructeur de Partie valide. + /// [Fact] public void TestSecondConstructeurValide() { @@ -106,8 +114,11 @@ namespace UnitTesting } } - } - + } + + /// + /// Test la méthode JouerDemanderJoueur de Partie. + /// [Fact] public void TestJouerDemanderJouer() { @@ -128,8 +139,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(demanderJoueurCalled); } - } - + } + + /// + /// Test la méthode JouerDebutPartie de Partie. + /// [Fact] public void TestJouerDebutPartie() { @@ -151,8 +165,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(debutPartieCalled); } - } - + } + + /// + /// Test la méthode DemanderJoueur de Partie. + /// [Fact] public void TestDemanderJoueur() { @@ -177,8 +194,11 @@ namespace UnitTesting joueurDemande.SeConnecter(joueurDemande); Assert.True(joueurConnecteCalled); } - } - + } + + /// + /// Test l'événement JoueurSeConnecterEventArgs de Partie. + /// [Fact] public void TestJoueurConnecte() { @@ -249,8 +269,11 @@ namespace UnitTesting Assert.Equal(1, tour); } } - } - + } + + /// + /// Test l'exception JoueurDejaPresentException de Partie. + /// [Fact] public void TestJoueurConnecteDejaPresent() { @@ -272,8 +295,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(appelee); - } - + } + + /// + /// Test l'exception NomJoueurInterditException de Partie. + /// [Fact] public void TestJoueurConnecteNomInterdit() { @@ -292,8 +318,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(appelee); - } - + } + + /// + /// Test la création d'un robot. + /// [Fact] public void TestRobot() { @@ -311,8 +340,11 @@ namespace UnitTesting partie.Jouer(); Assert.NotEmpty(partie.Robots); - } - + } + + /// + /// Test la méthode DebutPartie de Partie. + /// [Fact] public void TestDebutPartie() { @@ -361,8 +393,11 @@ namespace UnitTesting } } } - } - + } + + /// + /// Test la méthode NouveauTour de Partie. + /// [Fact] public void TestNouveauTour() { @@ -399,8 +434,11 @@ namespace UnitTesting Assert.True(demanderJoueurJouerEventTriggered); Assert.True(nouveauTourEventTriggered); - } - + } + + /// + /// Test la méthode AjouterCode de Partie et vérifie qu'il y a eu une incrémentation pour le nombre de tour. + /// [Fact] public void TestPlateauAjouterCodeIncrementation() { @@ -451,8 +489,11 @@ namespace UnitTesting Assert.Equal(1, partie.Tour); } - } - + } + + /// + /// Test la méthode AjouterCode de Partie et vérifie que la partie est terminée. + /// [Fact] public void PlateauAjouterCodeTerminee() { @@ -491,8 +532,11 @@ namespace UnitTesting Assert.True(partie.Termine); } } - } - + } + + /// + /// Test la méthode PartieTerminee de Partie et vérifie les gagnants et perdants. + /// [Fact] public void TestPartieTerminee() { @@ -534,8 +578,11 @@ namespace UnitTesting } } - } - + } + + /// + /// Test tous les événements de Partie. + /// [Fact] public void TestPartieEcoute() { @@ -603,8 +650,11 @@ namespace UnitTesting Assert.True(appel4); Assert.True(appel5); Assert.True(appel6); - } - + } + + /// + /// Test la méthode AjouterCode de Partie avec toutes ses composantes et les différentes fin. + /// [Fact] public void TestPartiePlateauAjouterCode() { diff --git a/Sources/UnitTesting/PlateauUT.cs b/Sources/UnitTesting/PlateauUT.cs index 7bc177d..21c2c50 100644 --- a/Sources/UnitTesting/PlateauUT.cs +++ b/Sources/UnitTesting/PlateauUT.cs @@ -1,73 +1,91 @@ -using CoreLibrary.Exceptions; -using System.Reflection; -using CoreLibrary.Core; -using Xunit; - -namespace UnitTesting -{ - public class PlateauUT - { - [Fact] - public void TestConstructeurValide() - { - Plateau plateau = new Plateau(4,12); - Assert.NotNull(plateau); - Assert.False(plateau.Victoire); - } - - [Fact] - public void TestConstructeurInvalide() - { - Assert.Throws(() => new Plateau(-1, 10)); - Assert.Throws(() => new Plateau(3, -1)); - } - - [Fact] - public void TestEstCompletTrue() - { - Plateau plateau = new Plateau(4, 3); - Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune)]; - Code code = new Code(4); - code.AjouterJeton(jetons[0]); - code.AjouterJeton(jetons[1]); - code.AjouterJeton(jetons[2]); - code.AjouterJeton(jetons[3]); - plateau.AjouterCode(code); - plateau.AjouterCode(code); - plateau.AjouterCode(code); - - bool estComplet = plateau.Complet; - - Assert.True(estComplet); - } - - [Fact] - public void TestEstCompletFalse() - { - Plateau plateau = new Plateau(4, 3); - Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune)]; - Code code = new Code(4); - code.AjouterJeton(jetons[0]); - code.AjouterJeton(jetons[1]); - code.AjouterJeton(jetons[2]); - code.AjouterJeton(jetons[3]); - plateau.AjouterCode(code); - plateau.AjouterCode(code); - - bool estComplet = plateau.Complet; - - Assert.False(estComplet); - } - +using CoreLibrary.Exceptions; +using System.Reflection; +using CoreLibrary.Core; +using Xunit; + +namespace UnitTesting +{ + /// + /// Classe test pour la classe Plateau. + /// + public class PlateauUT + { + /// + /// Test que le constructeur de Plateau soit valide. + /// + [Fact] + public void TestConstructeurValide() + { + Plateau plateau = new Plateau(4,12); + Assert.NotNull(plateau); + Assert.False(plateau.Victoire); + } + + /// + /// Test que le constructeur de Plateau soit invalide. + /// + [Fact] + public void TestConstructeurInvalide() + { + Assert.Throws(() => new Plateau(-1, 10)); + Assert.Throws(() => new Plateau(3, -1)); + } + + /// + /// Test la méthode EstComplet de Plateau et vérifie qu'il renvoie True. + /// + [Fact] + public void TestEstCompletTrue() + { + Plateau plateau = new Plateau(4, 3); + Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune)]; + Code code = new Code(4); + code.AjouterJeton(jetons[0]); + code.AjouterJeton(jetons[1]); + code.AjouterJeton(jetons[2]); + code.AjouterJeton(jetons[3]); + plateau.AjouterCode(code); + plateau.AjouterCode(code); + plateau.AjouterCode(code); + + bool estComplet = plateau.Complet; + + Assert.True(estComplet); + } + + /// + /// Test la méthode EstComplet de Plateau et vérifie qu'il renvoie False. + /// + [Fact] + public void TestEstCompletFalse() + { + Plateau plateau = new Plateau(4, 3); + Jeton[] jetons = [new Jeton(Couleur.Rouge), new Jeton(Couleur.Bleu), new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune)]; + Code code = new Code(4); + code.AjouterJeton(jetons[0]); + code.AjouterJeton(jetons[1]); + code.AjouterJeton(jetons[2]); + code.AjouterJeton(jetons[3]); + plateau.AjouterCode(code); + plateau.AjouterCode(code); + + bool estComplet = plateau.Complet; + + Assert.False(estComplet); + } + + /// + /// Test l'exception CodeCompletException de Plateau avec une taille de code supérieure à ce qui est défini. + /// [Fact] public void TestAjouterCodeTailleIncorrecte() { Plateau plateau = new Plateau(4, 10); Jeton[] jetons = new Jeton[] - { - new Jeton(Couleur.Rouge), - new Jeton(Couleur.Bleu), - new Jeton(Couleur.Blanc), + { + new Jeton(Couleur.Rouge), + new Jeton(Couleur.Bleu), + new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune) }; Code code = new Code(4); @@ -78,45 +96,54 @@ namespace UnitTesting Assert.Throws(() => code.AjouterJeton(new Jeton(Couleur.Bleu))); - } - - [Fact] - public void TestAjouterCodeIncomplet() - { - Plateau plateau = new Plateau(4, 10); - Code code = new Code(4); - - Assert.Throws(() => plateau.AjouterCode(code)); - } - - [Fact] - 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 TestGrilleAjouterCode() - { - Code code = new Code(4); - Couleur[] couleurs = Enum.GetValues(); + } + + /// + /// Test l'exception CodeIncompletException de Plateau avec un code incomplet. + /// + [Fact] + public void TestAjouterCodeIncomplet() + { + Plateau plateau = new Plateau(4, 10); + Code code = new Code(4); + + Assert.Throws(() => plateau.AjouterCode(code)); + } + + /// + /// Test la méthode AjouterCode de Plateau avec un bon code. + /// + [Fact] + 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); + } + + /// + /// Test la méthode AjouterCode de Plateau et vérifie la grille et ses composants. + /// + [Fact] + public void TestGrilleAjouterCode() + { + Code code = new Code(4); + Couleur[] couleurs = Enum.GetValues(); Plateau plateau = new Plateau(4, 12); Jeton[] jetons = new Jeton[] - { - new Jeton(Couleur.Rouge), - new Jeton(Couleur.Bleu), - new Jeton(Couleur.Blanc), + { + new Jeton(Couleur.Rouge), + new Jeton(Couleur.Bleu), + new Jeton(Couleur.Blanc), new Jeton(Couleur.Jaune) }; code.AjouterJeton(jetons[0]); @@ -124,59 +151,67 @@ namespace UnitTesting code.AjouterJeton(jetons[2]); code.AjouterJeton(jetons[3]); - plateau.AjouterCode(code); - (IEnumerable>, IEnumerable>) grille = plateau.Grille; - - var (jetonsGrille, indicateurs) = grille; - - - Assert.Single(jetonsGrille); - Assert.Equal(4, jetonsGrille.First().Count()); - - Assert.Single(indicateurs); - } - - [Fact] - public void TestGrilleEstVide() - { - Plateau plateau = new Plateau(4, 12); - (IEnumerable>, IEnumerable>) grille = plateau.Grille; - - var (jetons, indicateurs) = grille; - - Assert.Empty(jetons); - Assert.Empty(indicateurs); - } - - [Fact] - public void TestAjouterCode_GrilleComplete_ThrowsGrilleCompleteException() - { - Plateau plateau = new Plateau(4, 2); - Code codeComplet1 = new Code(4); - Code codeComplet2 = new Code(4); - Code codeComplet3 = new Code(4); - Jeton[] jetons = new Jeton[] - { - new Jeton(Couleur.Rouge), - new Jeton(Couleur.Bleu), - new Jeton(Couleur.Blanc), - new Jeton(Couleur.Jaune) - }; - foreach (Jeton jeton in jetons) - { - codeComplet1.AjouterJeton(jeton); - codeComplet2.AjouterJeton(jeton); - codeComplet3.AjouterJeton(jeton); - } - - plateau.AjouterCode(codeComplet1); - plateau.AjouterCode(codeComplet2); - - Assert.Throws(() => plateau.AjouterCode(codeComplet3)); - } - - - [Fact] + plateau.AjouterCode(code); + (IEnumerable>, IEnumerable>) grille = plateau.Grille; + + var (jetonsGrille, indicateurs) = grille; + + + Assert.Single(jetonsGrille); + Assert.Equal(4, jetonsGrille.First().Count()); + + Assert.Single(indicateurs); + } + + /// + /// Test que la grille du plateau est vide. + /// + [Fact] + public void TestGrilleEstVide() + { + Plateau plateau = new Plateau(4, 12); + (IEnumerable>, IEnumerable>) grille = plateau.Grille; + + var (jetons, indicateurs) = grille; + + Assert.Empty(jetons); + Assert.Empty(indicateurs); + } + + /// + /// Test l'exception GrilleCompleteException de Plateau. + /// + [Fact] + public void TestAjouterCode_GrilleComplete_ThrowsGrilleCompleteException() + { + Plateau plateau = new Plateau(4, 2); + Code codeComplet1 = new Code(4); + Code codeComplet2 = new Code(4); + Code codeComplet3 = new Code(4); + Jeton[] jetons = new Jeton[] + { + new Jeton(Couleur.Rouge), + new Jeton(Couleur.Bleu), + new Jeton(Couleur.Blanc), + new Jeton(Couleur.Jaune) + }; + foreach (Jeton jeton in jetons) + { + codeComplet1.AjouterJeton(jeton); + codeComplet2.AjouterJeton(jeton); + codeComplet3.AjouterJeton(jeton); + } + + plateau.AjouterCode(codeComplet1); + plateau.AjouterCode(codeComplet2); + + Assert.Throws(() => plateau.AjouterCode(codeComplet3)); + } + + /// + /// Test l'événement QuandPlateauAjouterCode de Plateau. + /// + [Fact] public void TestPlateauEcoute() { Plateau plateau = new Plateau(4, 2); @@ -193,10 +228,12 @@ namespace UnitTesting QuandPlateauAjouterCodeInfo?.Invoke(plateau, []); Assert.True(appel); - } - - - [Fact] + } + + /// + /// Test la méthode AjouterCode de Plateau et vérifie tous les cas d'arrêts. + /// + [Fact] public void TestAjouterCodeVictoire() { // Cas 1 : Victoire : false, code correct : false @@ -266,6 +303,6 @@ namespace UnitTesting VictoireInfo4.SetValue(plateau4, true); plateau4.AjouterCode(code4); - } - } -} + } + } +} diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index 3a3606d..2ddf292 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -3,8 +3,14 @@ using Xunit; namespace UnitTesting { + /// + /// Classe de test pour la classe ReglesClassiques. + /// public class ReglesClassiquesUT { + /// + /// Test les attributs de ReglesClassiques et vérifie qu'ils soient égaux. + /// [Fact] public void Test() { diff --git a/Sources/UnitTesting/ReglesDifficilesUT.cs b/Sources/UnitTesting/ReglesDifficilesUT.cs index 52c4357..64cf2e3 100644 --- a/Sources/UnitTesting/ReglesDifficilesUT.cs +++ b/Sources/UnitTesting/ReglesDifficilesUT.cs @@ -3,8 +3,14 @@ using Xunit; namespace UnitTesting { + /// + /// Classe de test pour la classe ReglesDifficiles. + /// public class ReglesDifficilesUT - { + { + /// + /// Test les attributs de ReglesDifficiles et vérifie qu'ils soient égaux. + /// [Fact] public void Test() {