Controle/TEST2024/TestPolynome.java

67 lines
1.7 KiB
Java

import static org.junit.Assert.assertTrue; // import static : une facilite offerte depuis java5 (pas besoin de mettre le prefixe)
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 TestPolynome{
@Test(expected=IllegalArgumentException.class)
public void LePlusGrandCoeffEstNonNul(){
Polynome p=new Polynome(new int[] {1,2,0});
}
@Test
public void EvaluerCorrect(){
Polynome p=new Polynome(new int[] {1,2,1});
assertEquals(0,p.evaluer(-1));
}
@Test
public void EvaluerEncore(){
Polynome p=new Polynome(new int[] {3,2,-1});
assertEquals(0,p.evaluer(3));
}
@Test
public void AffichageCorrect(){
Polynome p=new Polynome(new int[] {1,2,3});
assertEquals("3x^2+2x+1",p.toString());
}
@Test
public void AjoutPolynome(){
Polynome p=new Polynome(new int[] {1,2,3});
Polynome q=new Polynome(new int[] {9,-4});
Polynome s=p.add(q);
assertEquals(s.evaluer(0),10);
assertEquals(s.evaluer(1),11);
assertEquals(s.evaluer(3),31);
}
@Test
public void AjoutPolynomeEncore(){
Polynome p=new Polynome(new int[] {1,2,3});
Polynome q=new Polynome(new int[] {9,-4});
Polynome s=q.add(p);
assertEquals(s.evaluer(0),10);
assertEquals(s.evaluer(1),11);
assertEquals(s.evaluer(3),31);
}
@Test
public void SommeInverseCreePolynomeNul(){
Polynome p=new Polynome(new int[] {1,2,3,4,5,7});
Polynome pm=new Polynome(new int[] {-1,-2,-3,-4,-5,-7});
assertEquals(-1,p.add(pm).degre());
}
}