Merge pull request 'Up date Classe ♻️' (#11) from Fixing into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #11
Entities^2
Najlae LAMBARAA 3 years ago
commit 2589f98653

@ -5,11 +5,19 @@ namespace Data
{ {
public class Stub : IDataManager public class Stub : IDataManager
{ {
private List<Die> listDice = new List<Die>(); private List<Die> listDice = new List<Die>()
public void AddDice(Die addD)
{ {
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<Die> GetDices() public List<Die> GetDices()
{ {
AddDice( new NumberDie("de1", 2, 6));
AddDice(new NumberDie("de2", 1, 6));
return listDice; 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;
} }
} }
} }

@ -17,7 +17,7 @@ namespace Model
public ReadOnlyCollection<NumberDie> ListDice { get; set; } public ReadOnlyCollection<NumberDie> ListDice { get; set; }
private List<NumberDie> listDice = new List<NumberDie>(); //encapsulation des collections voir les videos partie 2 private List<NumberDie> listDice = new List<NumberDie>(); //encapsulation des collections voir les videos partie 2
public Game(string name, List<NumberDie> listDice) public Game(string name,IEnumerable<NumberDie> listDice)
{ {
Name = name; Name = name;
this.listDice.AddRange(listDice); this.listDice.AddRange(listDice);
@ -42,7 +42,7 @@ namespace Model
return name; return name;
} }
set private set
{ {
//Indique si une chaîne spécifiée est null, vide ou se compose uniquement d'espaces blancs //Indique si une chaîne spécifiée est null, vide ou se compose uniquement d'espaces blancs
if (string.IsNullOrWhiteSpace(value)) if (string.IsNullOrWhiteSpace(value))

@ -9,8 +9,8 @@ namespace Model
{ {
public interface IDataManager public interface IDataManager
{ {
public void AddDice(Die addD); public bool AddDice(Die addD);
public void RemoveDice(Die removeD); public bool RemoveDice(Die removeD);
public void clear(); public void clear();
public List<Die> GetDices(); public List<Die> GetDices();

@ -12,21 +12,31 @@ namespace Model
{ {
public IDataManager dataManager { get; set; } public IDataManager dataManager { get; set; }
public Manager(IDataManager data) public Manager(IDataManager data)
{ {
dataManager = data; dataManager = data;
} }
public bool AddDice(Die addD)
public void 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<Die> GetDice() public List<Die> GetDice()

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class NumberDie : Die public class NumberDie : Die, IEquatable<NumberDie>
{ {
private int min; private int min;
private int max; private int max;
@ -27,7 +27,7 @@ namespace Model
{ {
return min; return min;
} }
set private set
{ {
min = value; min = value;
} }
@ -38,33 +38,44 @@ namespace Model
{ {
return max; return max;
} }
set private set
{ {
max = value; max = value;
} }
} }
public override int RandomFace() public override int RandomFace()
{ {
int resultat = random.Next(min, max + 1); if (min < max)
return resultat; {
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) 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) public override bool Equals(object? obj)
{ {
//Check null //Check si la reference passer est null
if (ReferenceEquals(obj, null)) return false; if (ReferenceEquals(obj, null)) return false;
//Check reference equality //Check si reference passer is equality
if (ReferenceEquals(obj, this)) return true; if (ReferenceEquals(obj, this)) return true;
//Check types //Check if types is equality
if (GetType() != obj.GetType()) return false; if (GetType() != obj.GetType()) return false;
return Equals(obj as NumberDie); return Equals(obj as NumberDie);
} }
public override int GetHashCode()
{
return Name.GetHashCode() ^ Min.GetHashCode() ^ Max.GetHashCode();
}
} }
} }

@ -20,6 +20,7 @@ namespace Testeur
m.AddDice(nd); m.AddDice(nd);
//Assert //Assert
Assert.Equal("de1", nd.Name); Assert.Equal("de1", nd.Name);
} }
[Fact] [Fact]
public void TesterRemoveManager() public void TesterRemoveManager()

Loading…
Cancel
Save