From d8ed1711f8e1ef64c3ddadb6a1de3f3f813f522e Mon Sep 17 00:00:00 2001 From: Najlae Lambaraa Date: Sat, 22 Oct 2022 12:59:32 +0200 Subject: [PATCH] Up date Classe :recycle: --- Sources/MaSoluction/Data/Stub.cs | 31 +++++++++++++++++------ Sources/MaSoluction/Model/Game.cs | 4 +-- Sources/MaSoluction/Model/IDataManager.cs | 4 +-- Sources/MaSoluction/Model/Manager.cs | 24 +++++++++++++----- Sources/MaSoluction/Model/NumberDie.cs | 31 +++++++++++++++-------- Sources/MaSoluction/Testeur/TesterStub.cs | 1 + 6 files changed, 66 insertions(+), 29 deletions(-) diff --git a/Sources/MaSoluction/Data/Stub.cs b/Sources/MaSoluction/Data/Stub.cs index 017a740..0ea76d1 100644 --- a/Sources/MaSoluction/Data/Stub.cs +++ b/Sources/MaSoluction/Data/Stub.cs @@ -5,11 +5,19 @@ namespace Data { public class Stub : IDataManager { - private List listDice = new List(); - public void AddDice(Die addD) + private List listDice = new List() { - listDice.Add(addD); - + new NumberDie("de1", 2, 6), + new NumberDie("de2", 1, 6) + }; + public bool AddDice(Die addD) + { + if (addD != null) + { + listDice.Add(addD); + return true; + } + return false; } @@ -23,14 +31,21 @@ namespace Data public List GetDices() { - AddDice( new NumberDie("de1", 2, 6)); - AddDice(new NumberDie("de2", 1, 6)); + + + return listDice; } - public void RemoveDice(Die removeD) + public bool RemoveDice(Die removeD) { - listDice.Remove(removeD); + if (removeD!=null) + { + listDice.Remove(removeD); + return true; + } + + return false; } } } \ No newline at end of file diff --git a/Sources/MaSoluction/Model/Game.cs b/Sources/MaSoluction/Model/Game.cs index c10d675..8cb9ce6 100644 --- a/Sources/MaSoluction/Model/Game.cs +++ b/Sources/MaSoluction/Model/Game.cs @@ -17,7 +17,7 @@ namespace Model public ReadOnlyCollection ListDice { get; set; } private List listDice = new List(); //encapsulation des collections voir les videos partie 2 - public Game(string name, List listDice) + public Game(string name,IEnumerable listDice) { Name = name; this.listDice.AddRange(listDice); @@ -42,7 +42,7 @@ namespace Model return name; } - set + private set { //Indique si une chaîne spécifiée est null, vide ou se compose uniquement d'espaces blancs if (string.IsNullOrWhiteSpace(value)) diff --git a/Sources/MaSoluction/Model/IDataManager.cs b/Sources/MaSoluction/Model/IDataManager.cs index fead6f5..1fdaaad 100644 --- a/Sources/MaSoluction/Model/IDataManager.cs +++ b/Sources/MaSoluction/Model/IDataManager.cs @@ -9,8 +9,8 @@ namespace Model { public interface IDataManager { - public void AddDice(Die addD); - public void RemoveDice(Die removeD); + public bool AddDice(Die addD); + public bool RemoveDice(Die removeD); public void clear(); public List GetDices(); diff --git a/Sources/MaSoluction/Model/Manager.cs b/Sources/MaSoluction/Model/Manager.cs index 51f6345..53536d9 100644 --- a/Sources/MaSoluction/Model/Manager.cs +++ b/Sources/MaSoluction/Model/Manager.cs @@ -12,21 +12,31 @@ namespace Model { public IDataManager dataManager { get; set; } - + public Manager(IDataManager data) { dataManager = data; } - - - public void AddDice(Die addD) + public bool AddDice(Die addD) { - dataManager.AddDice(addD); + if(addD!=null) + { + dataManager.AddDice(addD); + return true; + } + return false; + + } - public void RemoveDice(Die removeD) + public bool RemoveDice(Die removeD) { - dataManager.RemoveDice(removeD); + if (removeD != null) + { + dataManager.RemoveDice(removeD); + return true; + } + return false; } public List GetDice() diff --git a/Sources/MaSoluction/Model/NumberDie.cs b/Sources/MaSoluction/Model/NumberDie.cs index cdf6661..f4d36b7 100644 --- a/Sources/MaSoluction/Model/NumberDie.cs +++ b/Sources/MaSoluction/Model/NumberDie.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Model { - public class NumberDie : Die + public class NumberDie : Die, IEquatable { private int min; private int max; @@ -27,7 +27,7 @@ namespace Model { return min; } - set + private set { min = value; } @@ -38,33 +38,44 @@ namespace Model { return max; } - set + private set { max = value; } } public override int RandomFace() { - int resultat = random.Next(min, max + 1); - return resultat; + if (min < max) + { + int resultat = random.Next(min, max + 1); + return resultat; + } + else throw new ArgumentException("le min doit etre inferieur de max "); } public bool Equals([AllowNull] NumberDie other) { - return Name == other.Name && Min == other.Min && Max == other.Max; + return Name==other.Name && Min == other.Min && Max == other.Max; } public override bool Equals(object? obj) { - //Check null + //Check si la reference passer est null if (ReferenceEquals(obj, null)) return false; - //Check reference equality + //Check si reference passer is equality if (ReferenceEquals(obj, this)) return true; - //Check types + //Check if types is equality if (GetType() != obj.GetType()) return false; return Equals(obj as NumberDie); } - + public override int GetHashCode() + { + return Name.GetHashCode() ^ Min.GetHashCode() ^ Max.GetHashCode(); + } + + + + } } diff --git a/Sources/MaSoluction/Testeur/TesterStub.cs b/Sources/MaSoluction/Testeur/TesterStub.cs index 53f4373..9b9966d 100644 --- a/Sources/MaSoluction/Testeur/TesterStub.cs +++ b/Sources/MaSoluction/Testeur/TesterStub.cs @@ -20,6 +20,7 @@ namespace Testeur m.AddDice(nd); //Assert Assert.Equal("de1", nd.Name); + } [Fact] public void TesterRemoveManager()