From 9ed620538d29563f18b6529e4e83f52c1f63ceac Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sat, 1 Oct 2022 23:28:42 +0200 Subject: [PATCH 1/8] . --- Sources/BowlingLib/Model/Frame.cs | 2 +- Sources/BowlingLib/Model/Partie.cs | 19 ++--- Sources/Tests/BowlingAppUnitTest/UTPartie.cs | 82 +++++++++++++++++++- 3 files changed, 90 insertions(+), 13 deletions(-) diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs index 7638e41..351d39e 100644 --- a/Sources/BowlingLib/Model/Frame.cs +++ b/Sources/BowlingLib/Model/Frame.cs @@ -148,7 +148,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/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index 2003ce0..a9c1dcc 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -30,21 +30,18 @@ namespace BowlingLib.Model for (int i = 0; i < Frames.Count; i++) { score += Frames[i].QuillesTombees; - if (i listParties = stubPartie.ListParties(); + Partie partie = listParties[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 (partie.Frames.Count==10) + { + 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(); + List listParties = stubPartie.ListParties(); + Partie partie = listParties[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); + } + } + + //Act + int? score = partie.GetScore(); + + //Assert + Assert.Equal(200, score); + } } } \ No newline at end of file From 23af5fd3da6f4aec2f02c94b4c3dd1fbab969ef7 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sat, 1 Oct 2022 23:28:42 +0200 Subject: [PATCH 2/8] . --- Sources/BowlingLib/Model/Frame.cs | 2 +- Sources/BowlingLib/Model/Partie.cs | 19 ++--- Sources/Tests/BowlingAppUnitTest/UTPartie.cs | 79 +++++++++++++++++++- 3 files changed, 87 insertions(+), 13 deletions(-) diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs index 7638e41..351d39e 100644 --- a/Sources/BowlingLib/Model/Frame.cs +++ b/Sources/BowlingLib/Model/Frame.cs @@ -148,7 +148,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/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index 2003ce0..a9c1dcc 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -30,21 +30,18 @@ namespace BowlingLib.Model for (int i = 0; i < Frames.Count; i++) { score += Frames[i].QuillesTombees; - if (i listParties = stubPartie.ListParties(); + Partie partie = listParties[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); + + } + + //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(); + List listParties = stubPartie.ListParties(); + Partie partie = listParties[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); + } + } + + //Act + int? score = partie.GetScore(); + + //Assert + Assert.Equal(200, score); + } } } \ No newline at end of file From cdce8d51cc5ebe4ff7250a37e087bea59d0706d1 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sun, 2 Oct 2022 10:29:58 +0200 Subject: [PATCH 3/8] fin --- Sources/BowlingLib/Model/Frame.cs | 6 +++ Sources/BowlingLib/Model/Partie.cs | 13 ++++++ Sources/Tests/BowlingAppUnitTest/UTPartie.cs | 44 +++++++++++++++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs index 351d39e..96a2700 100644 --- a/Sources/BowlingLib/Model/Frame.cs +++ b/Sources/BowlingLib/Model/Frame.cs @@ -36,6 +36,11 @@ namespace BowlingLib.Model this.IsSpare = false; } + /// + /// Lance une quille + /// + /// le nombre de quilles tombés + /// public void Lancer(int quillesTombees) { if (quillesTombees > QuillesRestantes) @@ -80,6 +85,7 @@ namespace BowlingLib.Model if (quillesTombees + this.Lancer1.QuillesTombees == 10) { this.IsSpare = true; + QuillesRestantes = 10; } } } diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index a9c1dcc..d591c9a 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -13,17 +13,30 @@ namespace BowlingLib.Model public List Frames { get; set; } + /// + /// 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; diff --git a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs index 4177389..da4505b 100644 --- a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs +++ b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs @@ -68,7 +68,11 @@ namespace BowlingAppUnitTest { partie.Frames[i].Lancer(5); partie.Frames[i].Lancer(5); - + if (i == 9) + { + partie.Frames[i].Lancer(5); + } + } //Act @@ -109,6 +113,10 @@ namespace BowlingAppUnitTest { partie.Frames[i].Lancer(5); partie.Frames[i].Lancer(5); + if (i==9) + { + partie.Frames[i].Lancer(5); + } } } @@ -118,5 +126,39 @@ namespace BowlingAppUnitTest //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(); + List listParties = stubPartie.ListParties(); + Partie partie = listParties[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 From 68462dfbf159aef0993dffd058b91b36e648a233 Mon Sep 17 00:00:00 2001 From: Arafamamadouelaphi <92931011+Arafamamadouelaphi@users.noreply.github.com> Date: Sun, 2 Oct 2022 18:57:48 +0100 Subject: [PATCH 4/8] encapsulation des classes --- Sources/BowlingLib/Model/Equipe.cs | 15 ++-- Sources/BowlingLib/Model/Frame.cs | 117 ++++++++++++++++++++++++----- Sources/BowlingLib/Model/Joueur.cs | 1 + Sources/BowlingLib/Model/Lancer.cs | 5 +- Sources/BowlingLib/Model/Partie.cs | 11 +-- 5 files changed, 118 insertions(+), 31 deletions(-) diff --git a/Sources/BowlingLib/Model/Equipe.cs b/Sources/BowlingLib/Model/Equipe.cs index 0ac6688..b509224 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; @@ -10,6 +11,11 @@ namespace BowlingLib.Model public class Equipe { private string nom; + public ReadOnlyCollection Joueurs + { + get; + private set; + } private List joueurs; public string Nom @@ -17,17 +23,12 @@ namespace BowlingLib.Model get { return nom; } set { nom = value; } } - - public List Joueurs - { - get { return joueurs; } - set { joueurs = value; } - } + private int numero; public Equipe(string nom) { this.nom = nom; - joueurs = new List(); + Joueurs = new ReadOnlyCollection(joueurs); } public void AjouterJoueur(Joueur joueur) diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs index 7638e41..38082cf 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,29 +9,111 @@ 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; @@ -54,7 +137,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 +149,7 @@ namespace BowlingLib.Model this.QuillesTombees += quillesTombees; if (this.IsStrike) { - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } @@ -77,7 +160,7 @@ namespace BowlingLib.Model } else { - if (quillesTombees + this.Lancer1.QuillesTombees == 10) + if (quillesTombees + this.Lancer1.QuillesTombees == MAX_QUILLE) { this.IsSpare = true; } @@ -90,7 +173,7 @@ namespace BowlingLib.Model this.QuillesTombees += quillesTombees; if (this.IsStrike) { - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } @@ -101,7 +184,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 +195,7 @@ namespace BowlingLib.Model } else { - if (quillesTombees + this.Lancer2.QuillesTombees == 10) + if (quillesTombees + this.Lancer2.QuillesTombees == MAX_QUILLE) { this.IsSpare = true; } @@ -139,7 +222,7 @@ namespace BowlingLib.Model } this.QuillesRestantes -= quillesTombees; this.QuillesTombees += quillesTombees; - if (quillesTombees == 10) + if (quillesTombees == MAX_QUILLE) { this.IsStrike = true; } diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index cf10721..0339eb3 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -25,6 +25,7 @@ namespace BowlingLib.Model get { return pseudo; } private set { pseudo = value; } } + } } 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/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index 9c78293..55faf52 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,20 +9,20 @@ namespace BowlingLib.Model { public class Partie { + public ReadOnlyCollection Frames; + public Joueur Joueur { get; private set; } - public Joueur Joueur { get; set; } - - public List Frames { get; set; } + private List frames; public Partie(Joueur joueur) { this.Joueur = joueur; - Frames = new List(); + Frames = new ReadOnlyCollection(frames); } public void AddFrame(Frame frame) { - Frames.Add(frame); + frames.Add(frame); } public int? GetScore() From a8ea131f846fa5e5d8d189d4907cb138c0f4a0b4 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sun, 2 Oct 2022 22:18:27 +0200 Subject: [PATCH 5/8] . --- Sources/BowlingLib/Model/Joueur.cs | 2 +- Sources/BowlingLib/Model/Partie.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index 0339eb3..3114ea2 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -12,7 +12,7 @@ namespace BowlingLib.Model public Joueur(string pseudo) { - this.pseudo = pseudo; + this.Pseudo = pseudo; if (pseudo == null || pseudo == "" || pseudo.Length < 3) { diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index ce1ab50..8430a9a 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -9,10 +9,10 @@ namespace BowlingLib.Model { public class Partie { - public ReadOnlyCollection Frames; + //public ReadOnlyCollection Frames; public Joueur Joueur { get; private set; } - private List frames; + public List Frames; /// /// Constructeur @@ -21,7 +21,7 @@ namespace BowlingLib.Model public Partie(Joueur joueur) { this.Joueur = joueur; - Frames = new ReadOnlyCollection(frames); + Frames = new List(); } /// @@ -30,7 +30,7 @@ namespace BowlingLib.Model /// public void AddFrame(Frame frame) { - frames.Add(frame); + Frames.Add(frame); } From 56a708e8d4b9268abb9765ebec4a465d3796d9be Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sun, 2 Oct 2022 22:18:27 +0200 Subject: [PATCH 6/8] . --- Sources/BowlingLib/Model/Frame.cs | 4 ++-- Sources/BowlingLib/Model/Joueur.cs | 2 +- Sources/BowlingLib/Model/Partie.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/BowlingLib/Model/Frame.cs b/Sources/BowlingLib/Model/Frame.cs index 50ea3a8..52030e5 100644 --- a/Sources/BowlingLib/Model/Frame.cs +++ b/Sources/BowlingLib/Model/Frame.cs @@ -38,11 +38,11 @@ namespace BowlingLib.Model { get { - return QuillesTombees; + return quillesTombees; } set { - this.QuillesTombees = value; + this.quillesTombees = value; } } private int quillesTombees; diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index 0339eb3..3114ea2 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -12,7 +12,7 @@ namespace BowlingLib.Model public Joueur(string pseudo) { - this.pseudo = pseudo; + this.Pseudo = pseudo; if (pseudo == null || pseudo == "" || pseudo.Length < 3) { diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index ce1ab50..8430a9a 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -9,10 +9,10 @@ namespace BowlingLib.Model { public class Partie { - public ReadOnlyCollection Frames; + //public ReadOnlyCollection Frames; public Joueur Joueur { get; private set; } - private List frames; + public List Frames; /// /// Constructeur @@ -21,7 +21,7 @@ namespace BowlingLib.Model public Partie(Joueur joueur) { this.Joueur = joueur; - Frames = new ReadOnlyCollection(frames); + Frames = new List(); } /// @@ -30,7 +30,7 @@ namespace BowlingLib.Model /// public void AddFrame(Frame frame) { - frames.Add(frame); + Frames.Add(frame); } From a182d5c5a45c7d195c3f553ffec7426248df73b4 Mon Sep 17 00:00:00 2001 From: Victor Perez NGOUNOU Date: Mon, 3 Oct 2022 15:30:43 +0000 Subject: [PATCH 7/8] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 0349b41fcd3eb92058476df82483e6d5c2ed3711 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Thu, 6 Oct 2022 07:16:45 +0200 Subject: [PATCH 8/8] Manager [#24] --- Sources/BowlingLib/Interface/IDataManager.cs | 18 +++ Sources/BowlingLib/Model/Equipe.cs | 3 + Sources/BowlingLib/Model/Joueur.cs | 17 +- Sources/BowlingLib/Model/Manager.cs | 147 ++++++++++++++++++ Sources/BowlingLib/Model/Partie.cs | 1 + Sources/BowlingStub/StubEquipe.cs | 55 +++++-- Sources/BowlingStub/StubJoueur.cs | 39 +++-- Sources/BowlingStub/StubPartie.cs | 29 +++- Sources/Tests/BowlingAppUnitTest/UTManager.cs | 62 ++++++++ Sources/Tests/BowlingAppUnitTest/UTPartie.cs | 16 +- .../BowlingAppUnitTest/UnitTestJoueur.cs | 29 +++- 11 files changed, 367 insertions(+), 49 deletions(-) create mode 100644 Sources/BowlingLib/Interface/IDataManager.cs create mode 100644 Sources/BowlingLib/Model/Manager.cs create mode 100644 Sources/Tests/BowlingAppUnitTest/UTManager.cs 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 b509224..dfcbdef 100644 --- a/Sources/BowlingLib/Model/Equipe.cs +++ b/Sources/BowlingLib/Model/Equipe.cs @@ -23,6 +23,9 @@ namespace BowlingLib.Model get { return nom; } set { nom = value; } } + + public object Id { get; set; } + private int numero; public Equipe(string nom) diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index 3114ea2..a916256 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -13,19 +13,22 @@ namespace BowlingLib.Model public Joueur(string pseudo) { this.Pseudo = pseudo; - - if (pseudo == null || pseudo == "" || pseudo.Length < 3) - { - throw new ArgumentException("Le pseudo ne peut pas être vide"); - } } 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 int Id { get; set; } } } 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 8430a9a..c24b567 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -11,6 +11,7 @@ namespace BowlingLib.Model { //public ReadOnlyCollection Frames; public Joueur Joueur { get; private set; } + public object Id { get; set; } public List Frames; diff --git a/Sources/BowlingStub/StubEquipe.cs b/Sources/BowlingStub/StubEquipe.cs index 4a76c4e..ccff2d8 100644 --- a/Sources/BowlingStub/StubEquipe.cs +++ b/Sources/BowlingStub/StubEquipe.cs @@ -1,26 +1,49 @@ using BowlingLib.Model; +using BowlingLib.Interface; using System; -public class StubEquipe +public class StubEquipe:IDataManager { - 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 da4505b..af3ed50 100644 --- a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs +++ b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs @@ -17,8 +17,8 @@ namespace BowlingAppUnitTest { //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)); @@ -51,8 +51,8 @@ namespace BowlingAppUnitTest { //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)); @@ -90,8 +90,8 @@ namespace BowlingAppUnitTest { //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)); @@ -135,8 +135,8 @@ namespace BowlingAppUnitTest { //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)); 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); + } + + } }