diff --git a/Sources/ConsoleApp1/ConsoleApp1.csproj b/Sources/ConsoleApp1/ConsoleApp1.csproj
new file mode 100644
index 0000000..180e42c
--- /dev/null
+++ b/Sources/ConsoleApp1/ConsoleApp1.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Sources/ConsoleApp1/Program.cs b/Sources/ConsoleApp1/Program.cs
new file mode 100644
index 0000000..a9b8284
--- /dev/null
+++ b/Sources/ConsoleApp1/Program.cs
@@ -0,0 +1,27 @@
+// Cas 3 - Plateau rempli, code mauvaise couleur
+using CoreLibrary.Core;
+using System.Reflection;
+
+Code code3 = new Code(1);
+code3.AjouterJeton(new Jeton(Couleur.Rouge));
+
+Plateau plateau3;
+Code? codeSecret3;
+do
+{
+ plateau3 = new Plateau(1, 1);
+
+ FieldInfo? codeSecretInfo3 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
+
+ codeSecret3 = codeSecretInfo3.GetValue(plateau2) as Code;
+ Assert.NotNull(codeSecret3);
+} while (codeSecret3.RecupererJeton(0).Equals(code3.RecupererJeton(0)));
+
+plateau3.AjouterCode(codeSecret3);
+
+MethodInfo? EstCodePossible3 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
+Assert.NotNull(EstCodePossible3);
+object? estPossibleObj3 = EstCodePossible3.Invoke(new Robot(), [plateau3, code3]);
+Assert.NotNull(estPossibleObj3);
+Assert.IsType(estPossibleObj3);
+Assert.False((bool)estPossibleObj3);
\ No newline at end of file
diff --git a/Sources/UnitTesting/PlateauUT.cs b/Sources/UnitTesting/PlateauUT.cs
index 1bb2469..7bc177d 100644
--- a/Sources/UnitTesting/PlateauUT.cs
+++ b/Sources/UnitTesting/PlateauUT.cs
@@ -1,78 +1,73 @@
-using CoreLibrary.Exceptions;
-using System.Reflection;
-using CoreLibrary.Core;
-using Xunit;
-using CoreLibrary.Joueurs;
-using CoreLibrary.Regles;
-using CoreLibrary;
-
-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
+{
+ 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);
+ }
+
[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);
@@ -83,45 +78,45 @@ 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();
+ }
+
+ [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();
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]);
@@ -129,59 +124,59 @@ 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);
+ }
+
+ [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]
public void TestPlateauEcoute()
{
Plateau plateau = new Plateau(4, 2);
@@ -198,10 +193,10 @@ namespace UnitTesting
QuandPlateauAjouterCodeInfo?.Invoke(plateau, []);
Assert.True(appel);
- }
-
-
- [Fact]
+ }
+
+
+ [Fact]
public void TestAjouterCodeVictoire()
{
// Cas 1 : Victoire : false, code correct : false
@@ -271,6 +266,6 @@ namespace UnitTesting
VictoireInfo4.SetValue(plateau4, true);
plateau4.AjouterCode(code4);
- }
- }
-}
+ }
+ }
+}
diff --git a/Sources/UnitTesting/RobotUT.cs b/Sources/UnitTesting/RobotUT.cs
new file mode 100644
index 0000000..a8dd1f8
--- /dev/null
+++ b/Sources/UnitTesting/RobotUT.cs
@@ -0,0 +1,73 @@
+using CoreLibrary;
+using CoreLibrary.Core;
+using CoreLibrary.Evenements;
+using CoreLibrary.Joueurs;
+using System.Reflection;
+using Xunit;
+
+namespace UnitTesting
+{
+ public class RobotUT
+ {
+ [Fact]
+ public void TestEstCodePossible()
+ {
+ // Cas 1 - Plateau vide
+ Plateau plateau1 = new Plateau(1, 1);
+ Code code1 = new Code(1);
+ code1.AjouterJeton(new Jeton(Couleur.Rouge));
+
+ MethodInfo? EstCodePossible1 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
+ Assert.NotNull(EstCodePossible1);
+ object? estPossibleObj1 = EstCodePossible1.Invoke(new Robot(), [plateau1, code1]);
+
+ Assert.NotNull(estPossibleObj1);
+ Assert.IsType(estPossibleObj1);
+ Assert.True((bool)estPossibleObj1);
+
+ // Cas 2 - Plateau rempli, code juste
+ Plateau plateau2 = new Plateau(1, 1);
+
+ FieldInfo? codeSecretInfo2 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
+ Assert.NotNull(codeSecretInfo2);
+
+ Code? codeSecret2 = codeSecretInfo2.GetValue(plateau2) as Code;
+ Assert.NotNull(codeSecret2);
+
+ plateau2.AjouterCode(codeSecret2);
+
+ MethodInfo? EstCodePossible2 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
+ Assert.NotNull(EstCodePossible2);
+ object? estPossibleObj2 = EstCodePossible2.Invoke(new Robot(), [plateau2, codeSecret2]);
+ Assert.NotNull(estPossibleObj2);
+ Assert.IsType(estPossibleObj2);
+ Assert.True((bool)estPossibleObj2);
+
+ // Cas 3 - Plateau rempli, code mauvaise couleur
+ Code code3 = new Code(1);
+ code3.AjouterJeton(new Jeton(Couleur.Rouge));
+
+ Plateau plateau3;
+ Code? codeSecret3;
+ do
+ {
+ plateau3 = new Plateau(1, 1);
+
+ FieldInfo? codeSecretInfo3 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
+ Assert.NotNull(codeSecretInfo3);
+
+ codeSecret3 = codeSecretInfo3.GetValue(plateau3) as Code;
+ Assert.NotNull(codeSecret3);
+ } while (codeSecret3.RecupererJeton(0).Equals(code3.RecupererJeton(0)));
+
+ plateau3.AjouterCode(codeSecret3);
+
+ MethodInfo? EstCodePossible3 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
+ Assert.NotNull(EstCodePossible3);
+ object? estPossibleObj3 = EstCodePossible3.Invoke(new Robot(), [plateau3, code3]);
+ Assert.NotNull(estPossibleObj3);
+ Assert.IsType(estPossibleObj3);
+ Assert.False((bool)estPossibleObj3);
+ }
+ }
+}
diff --git a/Sources/mastermind.sln b/Sources/mastermind.sln
index f45ac52..f07dc69 100644
--- a/Sources/mastermind.sln
+++ b/Sources/mastermind.sln
@@ -16,6 +16,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTesting", "UnitTesting\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistance", "Persistance\Persistance.csproj", "{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{2C86B541-6E8A-4C92-BC64-582413B22A49}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -44,6 +46,10 @@ Global
{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2C86B541-6E8A-4C92-BC64-582413B22A49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2C86B541-6E8A-4C92-BC64-582413B22A49}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2C86B541-6E8A-4C92-BC64-582413B22A49}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2C86B541-6E8A-4C92-BC64-582413B22A49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE