correction test
continuous-integration/drone/push Build is failing Details

master
parent 597a8b528c
commit 4ff70e4d51

@ -8,11 +8,16 @@
public Code(int tailleCode) public Code(int tailleCode)
{ {
if (tailleCode <= 0)
throw new CodeTailleInvalideException();
lesJetons = new Jeton?[tailleCode]; lesJetons = new Jeton?[tailleCode];
} }
public Code(IEnumerable<Jeton> jetons) public Code(IEnumerable<Jeton> jetons)
{ {
if (!jetons.Any())
throw new CodeTailleInvalideException();
lesJetons = new Jeton?[jetons.Count()]; lesJetons = new Jeton?[jetons.Count()];
foreach(Jeton jeton in jetons) foreach(Jeton jeton in jetons)
AjouterJeton(jeton); AjouterJeton(jeton);
@ -31,7 +36,9 @@
if(NbJetons <= 0) if(NbJetons <= 0)
throw new CodeTableauLesJetonsVideException(); throw new CodeTableauLesJetonsVideException();
lesJetons[NbJetons--] = null; lesJetons[NbJetons--] = null;
} }
public Jeton RecupererJeton(int indice) public Jeton RecupererJeton(int indice)

@ -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")
{ }
}
}

@ -17,8 +17,8 @@ namespace UnitTesting
[Fact] [Fact]
public void TestConstructorInvalidArguments() public void TestConstructorInvalidArguments()
{ {
Assert.Throws<ArgumentException>(() => new Code(0)); Assert.Throws<CodeTailleInvalideException>(() => new Code(0));
Assert.Throws<ArgumentException>(() => new Code(-1)); Assert.Throws<CodeTailleInvalideException>(() => new Code(-1));
} }
[Fact] [Fact]
@ -35,7 +35,7 @@ namespace UnitTesting
[Fact] [Fact]
public void TestSecondConstructorInvalidArguments() public void TestSecondConstructorInvalidArguments()
{ {
Assert.Throws<ArgumentException>(() => new Code([])); Assert.Throws<CodeTailleInvalideException>(() => new Code([]));
} }
[Fact] [Fact]
@ -67,9 +67,9 @@ namespace UnitTesting
public void TestSupprimerDernierJetonInvalid() public void TestSupprimerDernierJetonInvalid()
{ {
Code code = new Code([]); Code code = new Code([]);
Assert.Throws<Exception>(() => code.SupprimerDernierJeton()); Assert.Throws<CodeTableauLesJetonsVideException>(() => code.SupprimerDernierJeton());
Code code2 = new Code(4); Code code2 = new Code(4);
Assert.Throws<Exception>(() => code2.SupprimerDernierJeton()); Assert.Throws<CodeTableauLesJetonsVideException>(() => code2.SupprimerDernierJeton());
} }
[Fact] [Fact]

Loading…
Cancel
Save