From b1b19c77f5a7c1f3f4c39babe0c532869353401c Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Thu, 6 Jun 2024 11:56:22 +0200 Subject: [PATCH] code smell --- Sources/UnitTesting/PartieUT.cs | 90 +++++++++++++++++---------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/Sources/UnitTesting/PartieUT.cs b/Sources/UnitTesting/PartieUT.cs index 7aad0b4..cacb7d3 100644 --- a/Sources/UnitTesting/PartieUT.cs +++ b/Sources/UnitTesting/PartieUT.cs @@ -25,11 +25,11 @@ namespace UnitTesting [Fact] public void Partie_Constructeur_De_Copie_Cree_Une_Nouvelle_Instance_Avec_Les_Memes_Donnees() { - + IRegles regles = new ReglesClassiques(); Partie partieOriginale = new Partie(regles); - + FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance); @@ -37,63 +37,65 @@ namespace UnitTesting PropertyInfo? termineField = typeof(Partie).GetProperty("Termine", BindingFlags.Public | BindingFlags.Instance); - Dictionary? joueurs = joueursField.GetValue(partieOriginale) as Dictionary; - - if (joueurs != null) + if (joueursField != null && plateauxField != null) { - joueurs.Add("Joueur1", false); - joueurs.Add("Joueur2", true); - } - + Dictionary? joueurs = joueursField.GetValue(partieOriginale) as Dictionary; + if (joueurs != null) + { + joueurs.Add("Joueur1", false); + joueurs.Add("Joueur2", true); + } - List? plateaux = plateauxField.GetValue(partieOriginale) as List; + List? plateaux = plateauxField.GetValue(partieOriginale) as List; + if (plateaux != null) + { + plateaux.Add(new Plateau(4, 10)); + plateaux.Add(new Plateau(4, 10)); + } - if (plateaux != null) - { - plateaux.Add(new Plateau(4, 10)); - plateaux.Add(new Plateau(4, 10)); - } + - if(tourField != null) - tourField.SetValue(partieOriginale, 5); + if(tourField != null) + tourField.SetValue(partieOriginale, 5); - if (termineField != null) - termineField.SetValue(partieOriginale, false); + if (termineField != null) + termineField.SetValue(partieOriginale, false); - var partieCopiee = new Partie(partieOriginale); + var partieCopiee = new Partie(partieOriginale); - Dictionary? joueursCopie = joueursField.GetValue(partieCopiee) as Dictionary; - List? plateauxCopie = plateauxField.GetValue(partieCopiee) as List; - int? courantCopie = courantField.GetValue(partieCopiee) as int?; - int? tourCopie = tourField.GetValue(partieCopiee) as int?; - bool? termineCopie = termineField.GetValue(partieCopiee) as bool?; + Dictionary? joueursCopie = joueursField.GetValue(partieCopiee) as Dictionary; + List? plateauxCopie = plateauxField.GetValue(partieCopiee) as List; + int? courantCopie = courantField.GetValue(partieCopiee) as int?; + int? tourCopie = tourField.GetValue(partieCopiee) as int?; + bool? termineCopie = termineField.GetValue(partieCopiee) as bool?; - if (joueursCopie != null && plateauxCopie != null && courantCopie != null && tourCopie != null && termineCopie != null && joueurs != null && plateaux != null) - { - Assert.Equal(joueurs.Count, joueursCopie.Count); - Assert.Equal(plateaux.Count, plateauxCopie.Count); - Assert.Equal(5, tourCopie.Value); - Assert.False(termineCopie.Value); - Assert.Equal(regles, partieCopiee.Regles); - } - - foreach (String joueur in joueurs.Keys) - { - if(joueursCopie != null) + if (joueursCopie != null && plateauxCopie != null && courantCopie != null && tourCopie != null && termineCopie != null && joueurs != null && plateaux != null) { - Assert.True(joueursCopie.ContainsKey(joueur)); - Assert.Equal(joueurs[joueur], joueursCopie[joueur]); + Assert.Equal(joueurs.Count, joueursCopie.Count); + Assert.Equal(plateaux.Count, plateauxCopie.Count); + Assert.Equal(5, tourCopie.Value); + Assert.False(termineCopie.Value); + Assert.Equal(regles, partieCopiee.Regles); } + + foreach (String joueur in joueurs.Keys) + { + if(joueursCopie != null) + { + Assert.True(joueursCopie.ContainsKey(joueur)); + Assert.Equal(joueurs[joueur], joueursCopie[joueur]); + } - } + } - foreach (Plateau plateau in plateaux) - { - if (plateauxCopie != null) - Assert.Contains(plateau, plateauxCopie); + foreach (Plateau plateau in plateaux) + { + if (plateauxCopie != null) + Assert.Contains(plateau, plateauxCopie); + } } } }