From 268bac13507b6ab8652546fa6096d6a2e7107ea9 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sat, 1 Oct 2022 19:34:07 +0200 Subject: [PATCH 1/4] . --- Sources/BowlingLib/Model/Partie.cs | 19 +++++---- Sources/BowlingStub/StubPartie.cs | 22 +++++++++- Sources/Tests/BowlingAppUnitTest/UTPartie.cs | 45 ++++++++++++++++++++ 3 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 Sources/Tests/BowlingAppUnitTest/UTPartie.cs diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index 9c78293..2003ce0 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -30,17 +30,20 @@ namespace BowlingLib.Model for (int i = 0; i < Frames.Count; i++) { score += Frames[i].QuillesTombees; - if (Frames[i].IsStrike) + if (i listParties = new List(); + public StubPartie() + { + + + } + + //Fonction permettant de créer une partie pour chaque joueur + public List ListParties(int n = 10) + { + for (int i = 0; i < n; i++) + { + listParties.Add(new Partie(new Joueur("Joueur " + i + 1))); + } + return listParties; + } + + } } \ No newline at end of file diff --git a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs new file mode 100644 index 0000000..bf2b7b7 --- /dev/null +++ b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs @@ -0,0 +1,45 @@ +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 UTPartie + { + [Fact] + public void TestGetScore() + { + //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)); + partie.AddFrame(new Frame(10)); + + for (int i = 0; i < partie.Frames.Count; i++) + { + partie.Frames[i].Lancer(10); + } + + //Act + int? score = partie.GetScore(); + + //Assert + Assert.Equal(300, score); + } + } +} \ No newline at end of file From 9ed620538d29563f18b6529e4e83f52c1f63ceac Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Sat, 1 Oct 2022 23:28:42 +0200 Subject: [PATCH 2/4] . --- 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 3/4] . --- 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 4/4] 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