2023-06-21 10:21:19 +02:00
|
|
|
import static org.junit.Assert.assertTrue; // import static : une facilite offerte depuis java5 (pas besoin de mettre le préfixe)
|
2023-06-16 16:41:10 +02:00
|
|
|
import static org.junit.Assert.assertFalse; //
|
|
|
|
import static org.junit.Assert.assertEquals; //
|
|
|
|
import static org.junit.Assert.assertNull; //
|
|
|
|
import static org.junit.Assert.assertNotNull; //
|
|
|
|
import org.junit.Test;
|
|
|
|
import java.lang.StringBuilder;
|
|
|
|
import java.util.EmptyStackException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TestsFournisPileBornee{
|
|
|
|
|
|
|
|
// Une case vide contient forcement -1
|
|
|
|
@Test
|
|
|
|
public void CaseVideVautMoinsUn(){
|
|
|
|
PileBornee pb=new PileBornee(4);
|
|
|
|
pb.push(5);
|
|
|
|
pb.push(34);
|
|
|
|
pb.pop();
|
|
|
|
assertEquals(pb.t[3],-1);
|
|
|
|
assertEquals(pb.t[1],-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// On ne peut pas push si la pile est pleine
|
|
|
|
@Test(expected = IllegalStateException.class)
|
|
|
|
public void PushSurPilePleine(){
|
|
|
|
PileBornee pb=new PileBornee(26);
|
|
|
|
for(int i=0;i<26;i++){
|
|
|
|
pb.push(3*i);
|
|
|
|
}
|
|
|
|
pb.push(0);
|
|
|
|
}
|
|
|
|
|
2023-06-21 10:21:19 +02:00
|
|
|
//On ne peut pas push un nombre negatif
|
2023-06-16 16:41:10 +02:00
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
|
|
public void NonNegativeInteger(){
|
|
|
|
PileBornee pb=new PileBornee(5);
|
|
|
|
pb.push(-5);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Contient renvoie vrai si n est dans la pile
|
|
|
|
@Test
|
|
|
|
public void ContientCeQuonAMis(){
|
|
|
|
PileBornee pb=new PileBornee(42);
|
|
|
|
pb.push(12);
|
|
|
|
pb.push(1138);
|
|
|
|
pb.push(48);
|
|
|
|
pb.push(12);
|
|
|
|
assertTrue(pb.contient(12));
|
|
|
|
assertTrue(pb.contient(1138));
|
|
|
|
}
|
|
|
|
|
|
|
|
// toString renvoie un affichage correspondant à ce qu'on attend
|
|
|
|
@Test
|
|
|
|
public void AffichageCorrect(){
|
|
|
|
PileBornee pb=new PileBornee(12);
|
|
|
|
pb.push(1);
|
|
|
|
pb.push(2);
|
|
|
|
pb.push(3);
|
|
|
|
assertEquals("[1,2,3]",pb.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|