From 4ff70e4d51ff56ee7c9e1743b954037e80f5a186 Mon Sep 17 00:00:00 2001 From: "camille.turpin-etienne" Date: Mon, 6 May 2024 11:40:38 +0200 Subject: [PATCH] correction test --- Sources/CoreLibrary/Code.cs | 9 ++++++++- Sources/CoreLibrary/CodeTailleInvalideException.cs | 14 ++++++++++++++ Sources/UnitTesting/CodeUT.cs | 10 +++++----- 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 Sources/CoreLibrary/CodeTailleInvalideException.cs diff --git a/Sources/CoreLibrary/Code.cs b/Sources/CoreLibrary/Code.cs index 4c00021..3c3b77d 100644 --- a/Sources/CoreLibrary/Code.cs +++ b/Sources/CoreLibrary/Code.cs @@ -7,12 +7,17 @@ public int NbJetons { get; private set; } = 0; public Code(int tailleCode) - { + { + if (tailleCode <= 0) + throw new CodeTailleInvalideException(); lesJetons = new Jeton?[tailleCode]; } public Code(IEnumerable jetons) { + if (!jetons.Any()) + throw new CodeTailleInvalideException(); + lesJetons = new Jeton?[jetons.Count()]; foreach(Jeton jeton in jetons) AjouterJeton(jeton); @@ -31,7 +36,9 @@ if(NbJetons <= 0) throw new CodeTableauLesJetonsVideException(); + lesJetons[NbJetons--] = null; + } public Jeton RecupererJeton(int indice) diff --git a/Sources/CoreLibrary/CodeTailleInvalideException.cs b/Sources/CoreLibrary/CodeTailleInvalideException.cs new file mode 100644 index 0000000..4fcadeb --- /dev/null +++ b/Sources/CoreLibrary/CodeTailleInvalideException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreLibrary +{ + public class CodeTailleInvalideException : Exception + { + public CodeTailleInvalideException() : base("La taille du tableau de code est inférieure ou égale à 0") + { } + } +} diff --git a/Sources/UnitTesting/CodeUT.cs b/Sources/UnitTesting/CodeUT.cs index 516d2a4..c25e27c 100644 --- a/Sources/UnitTesting/CodeUT.cs +++ b/Sources/UnitTesting/CodeUT.cs @@ -17,8 +17,8 @@ namespace UnitTesting [Fact] public void TestConstructorInvalidArguments() { - Assert.Throws(() => new Code(0)); - Assert.Throws(() => new Code(-1)); + Assert.Throws(() => new Code(0)); + Assert.Throws(() => new Code(-1)); } [Fact] @@ -35,7 +35,7 @@ namespace UnitTesting [Fact] public void TestSecondConstructorInvalidArguments() { - Assert.Throws(() => new Code([])); + Assert.Throws(() => new Code([])); } [Fact] @@ -67,9 +67,9 @@ namespace UnitTesting public void TestSupprimerDernierJetonInvalid() { Code code = new Code([]); - Assert.Throws(() => code.SupprimerDernierJeton()); + Assert.Throws(() => code.SupprimerDernierJeton()); Code code2 = new Code(4); - Assert.Throws(() => code2.SupprimerDernierJeton()); + Assert.Throws(() => code2.SupprimerDernierJeton()); } [Fact]