diff --git a/README.md b/README.md index 8d1bb87..297402c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Build Status](https://codefirst.iut.uca.fr/api/badges/victor_perez.ngounou/BowlingScoreApp/status.svg)](https://codefirst.iut.uca.fr/victor_perez.ngounou/BowlingScoreApp) -[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=BowlingScoreApp&metric=alert_status)](https://codefirst.iut.uca.fr/sonar/dashboard?id=BowlingScoreApp) +[![Quality Gate Status](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=BowlingScoreApp&metric=alert_status&token=squ_8476cf8c9c3d3acdcf6042e2075498afbe697e52)](https://codefirst.iut.uca.fr/sonar/dashboard?id=BowlingScoreApp) [![Bugs](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=BowlingScoreApp&metric=bugs)](https://codefirst.iut.uca.fr/sonar/dashboard?id=BowlingScoreApp) [![Code Smells](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=BowlingScoreApp&metric=code_smells)](https://codefirst.iut.uca.fr/sonar/dashboard?id=BowlingScoreApp) [![Coverage](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=BowlingScoreApp&metric=coverage)](https://codefirst.iut.uca.fr/sonar/dashboard?id=BowlingScoreApp) diff --git a/Sources/BowlingLib/Interface/IDataManager.cs b/Sources/BowlingLib/Interface/IDataManager.cs new file mode 100644 index 0000000..b509d9b --- /dev/null +++ b/Sources/BowlingLib/Interface/IDataManager.cs @@ -0,0 +1,18 @@ +using BowlingLib.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Interface +{ + public interface IDataManager + { + void Add(Data data); + void Delete(Data data); + void Update(Data data); + IEnumerable GetAll(); + IEnumerable GetAll(int n, int j); + } +} diff --git a/Sources/BowlingLib/Model/Equipe.cs b/Sources/BowlingLib/Model/Equipe.cs index f2fb05d..f06f16b 100644 --- a/Sources/BowlingLib/Model/Equipe.cs +++ b/Sources/BowlingLib/Model/Equipe.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -31,6 +32,9 @@ namespace BowlingLib.Model // foreach (Joueur nouv in joueurs) AjouterJoueur(nouv); } + public object Id { get; set; } + + private int numero; public Equipe(string nom) { diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs index 7638e41..52030e5 100644 --- a/Sources/BowlingLib/Model/Frame.cs +++ b/Sources/BowlingLib/Model/Frame.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,34 +9,121 @@ namespace BowlingLib.Model { public class Frame { - public int Numero { get; set; } + const int MAX_QUILLE = 10; + public int Numero { + get + { return numero; } + set + { + this.numero = value; + } + } + private int numero; - public int QuillesRestantes { get; set; } - public int QuillesTombees { get; set; } + public int QuillesRestantes + { get + { + return quillesRestantes; + } + set + { + this.quillesRestantes = value; + } + } + private int quillesRestantes; - public bool IsStrike { get; set; } + public int QuillesTombees + { + get + { + return quillesTombees; + } + set + { + this.quillesTombees = value; + } + } + private int quillesTombees; + + public bool IsStrike { + get { + return isStrike; + } + set{ + this.isStrike = value; + } + } + private bool isStrike; - public bool IsSpare { get; set; } + public bool IsSpare + { + get + { + return isPark; + } + set + { + this.isPark = value; + } + } + private bool isPark; - public bool IsFinished { get; set; } + public bool IsFinished + { + get + { + return isFinished; + } + set + { + this.isFinished = value; + } - public Lancer Lancer1 { get; set; } + } + private bool isFinished; - public Lancer Lancer2 { get; set; } + public Lancer Lancer1 + { + get + { + return lancer1; + } + set + { + this.lancer1 = value; + } + } + private Lancer lancer1; - public Lancer Lancer3 { get; set; } + public Lancer Lancer2 + { + get { return lancer2; } + set { this.lancer2 = value; } + } + private Lancer lancer2; + public Lancer Lancer3 + { + get { return lancer3; } + set { this.lancer3 = value; } + } + private Lancer lancer3; public Frame(int numero) { this.Numero = numero; - this.QuillesRestantes = 10; + this.QuillesRestantes = MAX_QUILLE; this.IsFinished = false; this.IsStrike = false; this.IsSpare = false; } + /// + /// Lance une quille + /// + /// le nombre de quilles tombés + /// public void Lancer(int quillesTombees) { if (quillesTombees > QuillesRestantes) @@ -54,7 +142,7 @@ namespace BowlingLib.Model this.Lancer1 = new Lancer(quillesTombees); this.QuillesRestantes -= quillesTombees; this.QuillesTombees += quillesTombees; - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } @@ -66,7 +154,7 @@ namespace BowlingLib.Model this.QuillesTombees += quillesTombees; if (this.IsStrike) { - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } @@ -77,9 +165,10 @@ namespace BowlingLib.Model } else { - if (quillesTombees + this.Lancer1.QuillesTombees == 10) + if (quillesTombees + this.Lancer1.QuillesTombees == MAX_QUILLE) { this.IsSpare = true; + QuillesRestantes = 10; } } } @@ -90,7 +179,7 @@ namespace BowlingLib.Model this.QuillesTombees += quillesTombees; if (this.IsStrike) { - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } @@ -101,7 +190,7 @@ namespace BowlingLib.Model } else if (this.IsSpare) { - if (quillesTombees + this.Lancer2.QuillesTombees == 10) + if (quillesTombees + this.Lancer2.QuillesTombees == MAX_QUILLE) { this.IsSpare = true; } @@ -112,7 +201,7 @@ namespace BowlingLib.Model } else { - if (quillesTombees + this.Lancer2.QuillesTombees == 10) + if (quillesTombees + this.Lancer2.QuillesTombees == MAX_QUILLE) { this.IsSpare = true; } @@ -139,7 +228,7 @@ namespace BowlingLib.Model } this.QuillesRestantes -= quillesTombees; this.QuillesTombees += quillesTombees; - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } @@ -148,7 +237,7 @@ namespace BowlingLib.Model this.IsSpare = true; } } - if (this.QuillesRestantes == 0 || this.Lancer2 != null) + if (this.QuillesRestantes == 0 || (this.Lancer2 != null && this.Numero != 10)) { this.IsFinished = true; } diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index 660acd0..73102a1 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -11,20 +11,22 @@ namespace BowlingLib.Model private string pseudo; public Joueur(string pseudo) - { - - if (pseudo == null || pseudo == "" || pseudo.Length < 3) - { - throw new ArgumentException("Le pseudo ne peut pas être vide"); - } - - this.pseudo = pseudo; + { + this.Pseudo = pseudo; } public string Pseudo { get { return pseudo; } - private set { pseudo = value; } + set + { + + pseudo = value; + if (pseudo == null || pseudo == "" || pseudo.Length < 3) + { + throw new ArgumentException("Le pseudo ne peut pas être vide"); + } + } } public override bool Equals(object obj) @@ -33,5 +35,6 @@ namespace BowlingLib.Model pseudo == joueur.pseudo && Pseudo == joueur.Pseudo; } + public int Id { get; set; } } } diff --git a/Sources/BowlingLib/Model/Lancer.cs b/Sources/BowlingLib/Model/Lancer.cs index ad447ce..52c23e7 100644 --- a/Sources/BowlingLib/Model/Lancer.cs +++ b/Sources/BowlingLib/Model/Lancer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,10 +11,10 @@ namespace BowlingLib.Model { private int quillesTombees; - public int QuillesTombees + public int QuillesTombees { get { return quillesTombees; } - set + private set { if (value < 0 || value > 10) { diff --git a/Sources/BowlingLib/Model/Manager.cs b/Sources/BowlingLib/Model/Manager.cs new file mode 100644 index 0000000..74d06b4 --- /dev/null +++ b/Sources/BowlingLib/Model/Manager.cs @@ -0,0 +1,147 @@ +using BowlingLib.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Manager + { + public IDataManager joueurManager { get; private set; } + public IDataManager partieManager { get; private set; } + public IDataManager equipeManager { get; private set; } + + public Manager(IDataManager joueurManager) + { + this.joueurManager = joueurManager; + } + + public Manager(IDataManager partieManager) + { + this.partieManager = partieManager; + } + + /// + /// Ajoute un joueur à la liste des joueurs + /// + /// + public Manager(IDataManager equipeManager) + { + this.equipeManager = equipeManager; + } + + /// + /// Ajoute un joueur à la liste des joueurs + /// + /// + public void AddJoueur(Joueur joueur) + { + joueurManager.Add(joueur); + } + + /// + /// Ajoute une partie à la liste des parties + /// + /// + public void AddPartie(Partie partie) + { + partieManager.Add(partie); + } + + /// + /// Ajoute une équipe à la liste des équipes + /// + /// + public void AddEquipe(Equipe equipe) + { + equipeManager.Add(equipe); + } + + /// + /// Retourne la liste des joueurs + /// + /// + public void DeleteJoueur(Joueur joueur) + { + joueurManager.Delete(joueur); + } + + /// + /// Supprime une partie + /// + /// + public void DeletePartie(Partie partie) + { + partieManager.Delete(partie); + } + + /// + /// Supprime une équipe + /// + /// + public void DeleteEquipe(Equipe equipe) + { + equipeManager.Delete(equipe); + } + + /// + /// Retourne la liste des joueurs + /// + /// + public void UpdateJoueur(Joueur joueur) + { + joueurManager.Update(joueur); + } + + /// + /// Met à jour une partie + /// + /// + public void UpdatePartie(Partie partie) + { + partieManager.Update(partie); + } + + /// + /// Met à jour une équipe + /// + /// + public void UpdateEquipe(Equipe equipe) + { + equipeManager.Update(equipe); + } + + /// + /// Retourne la liste des joueurs + /// + /// + public IEnumerable GetAllJoueur() + { + return joueurManager.GetAll(); + } + + /// + /// Retourne les dernières parties du joueur + /// + /// + public IEnumerable GetAllPartie() + { + return partieManager.GetAll(); + } + + /// + /// Retourne les Equipe d'une partie + /// + /// + public IEnumerable GetAllEquipe() + { + return equipeManager.GetAll(); + } + + + + + } +} diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index 2003ce0..c24b567 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,43 +9,54 @@ namespace BowlingLib.Model { public class Partie { + //public ReadOnlyCollection Frames; + public Joueur Joueur { get; private set; } + public object Id { get; set; } - public Joueur Joueur { get; set; } - - public List Frames { get; set; } + public List Frames; + /// + /// Constructeur + /// + /// public Partie(Joueur joueur) { this.Joueur = joueur; Frames = new List(); } + /// + /// Ajoute un frame à la partie + /// + /// public void AddFrame(Frame frame) { Frames.Add(frame); } + + /// + /// Calcule le score de la partie + /// + /// le Score d'une partie public int? GetScore() { int? score = 0; for (int i = 0; i < Frames.Count; i++) { score += Frames[i].QuillesTombees; - if (i { - private List listEquipes = new List(); - public StubEquipe() - { - } - - public List ListEquipes(int n = 10, int j = 2) - { - for (int i = 0; i < n; i++) - { - listEquipes.Add(new Equipe("Equipe " + i + 1)); - - for(int k = 0; k < j; k++) + private List listEquipes = new List(); + public StubEquipe() + { + } + + public void Add(Equipe data) + { + listEquipes.Add(data); + } + + public void Delete(Equipe data) + { + listEquipes.Remove(data); + } + + public IEnumerable GetAll(int n = 10, int j = 2) + { + for (int i = 0; i < n; i++) + { + this.Add(new Equipe("Equipe " + i + 1)); + + for (int k = 0; k < j; k++) { - listEquipes.ElementAt(i).AjouterJoueur(new Joueur("Joueur " + i + 1 + "-" + k + 1)); + listEquipes.ElementAt(i).AjouterJoueur(new Joueur("Joueur " + i + 1 + "-" + k + 1)); + + } + } + return listEquipes; + } - } - } + public IEnumerable GetAll() + { return listEquipes; } + //mise à jour d'une équipe + public void Update(Equipe data) + { + int index = listEquipes.FindIndex(x => x.Id == data.Id); + listEquipes[index] = data; + } + } diff --git a/Sources/BowlingStub/StubJoueur.cs b/Sources/BowlingStub/StubJoueur.cs index 5fc7ec1..8bfdfb6 100644 --- a/Sources/BowlingStub/StubJoueur.cs +++ b/Sources/BowlingStub/StubJoueur.cs @@ -1,20 +1,41 @@ using BowlingLib.Model; +using BowlingLib.Interface; using System; -public class StubJoueur +public class StubJoueur : IDataManager + { -private List listJoueurs = new List(); - public StubJoueur() - { - } + private List listJoueurs = new List(); + + + public void Add(Joueur data) + { + listJoueurs.Add(data); + } + + public void Delete(Joueur data) + { + listJoueurs.Remove(data); + } - public List ListJoueurs(int n = 10) + public IEnumerable GetAll() { - for (int i = 0; i < n; i++) + return listJoueurs; + } + + public IEnumerable GetAll(int n=10, int j=0) + { + for (int i = 0; i < n; i++) { - listJoueurs.Add(new Joueur("Joueur " + i + 1)); - } + Add(new Joueur("Joueur " + i + 1)); + } return listJoueurs; } + public void Update(Joueur data) + { + int index = listJoueurs.FindIndex(x => x.Id == data.Id); + listJoueurs[index] = data; + } + } diff --git a/Sources/BowlingStub/StubPartie.cs b/Sources/BowlingStub/StubPartie.cs index 574254f..9e0651c 100644 --- a/Sources/BowlingStub/StubPartie.cs +++ b/Sources/BowlingStub/StubPartie.cs @@ -1,18 +1,28 @@ using BowlingLib.Model; +using BowlingLib.Interface; namespace BowlingStub { - public class StubPartie + public class StubPartie:IDataManager { - List listParties = new List(); - public StubPartie() + private List listParties = new List(); + + public void Add(Partie data) { - + listParties.Add(data); + } + public void Delete(Partie data) + { + listParties.Remove(data); + } + + public IEnumerable GetAll() + { + return listParties; } - //Fonction permettant de créer une partie pour chaque joueur - public List ListParties(int n = 10) + public IEnumerable GetAll(int n=10, int j=0) { for (int i = 0; i < n; i++) { @@ -20,9 +30,12 @@ namespace BowlingStub } return listParties; } - - + public void Update(Partie data) + { + int index = listParties.FindIndex(x => x.Id == data.Id); + listParties[index] = data; + } } } \ No newline at end of file diff --git a/Sources/Tests/BowlingAppUnitTest/UTManager.cs b/Sources/Tests/BowlingAppUnitTest/UTManager.cs new file mode 100644 index 0000000..2d628a6 --- /dev/null +++ b/Sources/Tests/BowlingAppUnitTest/UTManager.cs @@ -0,0 +1,62 @@ +using BowlingLib.Model; +using BowlingStub; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace BowlingAppUnitTest +{ + public class UTManager + { + //test de la méthode AddJoueur using MemberData + [Fact] + public void TestAddJoueur() //Test de la méthode AddJoueur + { + //Arrange + Joueur joueur = new Joueur("Pierre"); + Manager manager = new Manager(new StubJoueur()); + + //Act + manager.AddJoueur(joueur); + + //Assert + Assert.Single(manager.joueurManager.GetAll()); + } + + //Test de la méthode AddPartie + [Fact] + public void TestAddPartie() //Test de la méthode AddPartie + { + //Arrange + Partie partie = new Partie(new Joueur("Pierre")); + Manager manager = new Manager(new StubPartie()); + + //Act + manager.AddPartie(partie); + + //Assert + Assert.Single(manager.partieManager.GetAll()); + } + + //Test de la méthode AddEquipe + //[Fact] + + //public void TestAddEquipe() //Test de la méthode AddEquipe + //{ + // //Arrange + // Equipe equipe = new Equipe("Equipe 1"); + // Manager manager = new Manager(new StubEquipe()); + + // //Act + // manager.AddEquipe(equipe); + + // //Assert + // Assert.Single(manager.equipeManager.GetAll()); + //} + + + } +} diff --git a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs index bf2b7b7..af3ed50 100644 --- a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs +++ b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs @@ -11,13 +11,14 @@ namespace BowlingAppUnitTest { public class UTPartie { + //le cas ou le joueur ne fait que des strikes [Fact] public void TestGetScore() { //Arrange StubPartie stubPartie = new StubPartie(); - List listParties = stubPartie.ListParties(); - Partie partie = listParties[0]; + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); partie.AddFrame(new Frame(1)); partie.AddFrame(new Frame(2)); partie.AddFrame(new Frame(3)); @@ -28,7 +29,7 @@ namespace BowlingAppUnitTest partie.AddFrame(new Frame(8)); partie.AddFrame(new Frame(9)); partie.AddFrame(new Frame(10)); - partie.AddFrame(new Frame(10)); + partie.AddFrame(new Frame(11)); for (int i = 0; i < partie.Frames.Count; i++) { @@ -41,5 +42,123 @@ namespace BowlingAppUnitTest //Assert Assert.Equal(300, score); } + + //le cas ou le joueur fait que des spares + + [Fact] + + public void TestGetScore2() + { + //Arrange + StubPartie stubPartie = new StubPartie(); + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); + partie.AddFrame(new Frame(1)); + partie.AddFrame(new Frame(2)); + partie.AddFrame(new Frame(3)); + partie.AddFrame(new Frame(4)); + partie.AddFrame(new Frame(5)); + partie.AddFrame(new Frame(6)); + partie.AddFrame(new Frame(7)); + partie.AddFrame(new Frame(8)); + partie.AddFrame(new Frame(9)); + partie.AddFrame(new Frame(10)); + + for (int i = 0; i < partie.Frames.Count; i++) + { + partie.Frames[i].Lancer(5); + partie.Frames[i].Lancer(5); + if (i == 9) + { + partie.Frames[i].Lancer(5); + } + + } + + //Act + int? score = partie.GetScore(); + + //Assert + Assert.Equal(150, score); + } + + //le cas ou le joueur fait que des spares et des strikes + + [Fact] + + public void TestGetScore3() + { + //Arrange + StubPartie stubPartie = new StubPartie(); + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); + partie.AddFrame(new Frame(1)); + partie.AddFrame(new Frame(2)); + partie.AddFrame(new Frame(3)); + partie.AddFrame(new Frame(4)); + partie.AddFrame(new Frame(5)); + partie.AddFrame(new Frame(6)); + partie.AddFrame(new Frame(7)); + partie.AddFrame(new Frame(8)); + partie.AddFrame(new Frame(9)); + partie.AddFrame(new Frame(10)); + + for (int i = 0; i < partie.Frames.Count; i++) + { + if (i % 2 == 0) + { + partie.Frames[i].Lancer(10); + } + else + { + partie.Frames[i].Lancer(5); + partie.Frames[i].Lancer(5); + if (i==9) + { + partie.Frames[i].Lancer(5); + } + } + } + + //Act + int? score = partie.GetScore(); + + //Assert + Assert.Equal(200, score); + } + + //le cas ou le joueur ne fait aucun strike ou spare + + [Fact] + + public void TestGetScore4() + { + //Arrange + StubPartie stubPartie = new StubPartie(); + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); + partie.AddFrame(new Frame(1)); + partie.AddFrame(new Frame(2)); + partie.AddFrame(new Frame(3)); + partie.AddFrame(new Frame(4)); + partie.AddFrame(new Frame(5)); + partie.AddFrame(new Frame(6)); + partie.AddFrame(new Frame(7)); + partie.AddFrame(new Frame(8)); + partie.AddFrame(new Frame(9)); + partie.AddFrame(new Frame(10)); + + for (int i = 0; i < partie.Frames.Count; i++) + { + partie.Frames[i].Lancer(5); + partie.Frames[i].Lancer(4); + } + + //Act + int? score = partie.GetScore(); + + //Assert + Assert.Equal(90, score); + } } } \ No newline at end of file diff --git a/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs b/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs index 83eeb4e..fa00da9 100644 --- a/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs +++ b/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using BowlingLib.Model; using Xunit; @@ -75,7 +76,33 @@ namespace Test.BowlingAppUnitTest public void TestJoueurStub() { StubJoueur stub = new StubJoueur(); - Assert.Equal(10, stub.ListJoueurs(10).Count); + Assert.Equal(10, stub.GetAll(10).Count()); } + + + //tester la methode remove + [Fact] + public void TestRemove() + { + StubJoueur stub = new StubJoueur(); + stub.Add(j); + stub.Delete(j); + //Compter le nombre de joueur dans un objet IEnumerable + Assert.Equal(0, stub.GetAll().Count()); + } + + //tester la methode update avec les members Data + [Fact] + public void TestUpdate() + { + StubJoueur stub = new StubJoueur(); + Joueur j = new Joueur("Paul"); + stub.Add(j); + j.Pseudo = "Augustin"; + stub.Update(j); + Assert.Equal("Augustin", stub.GetAll().First().Pseudo); + } + + } }