projet-mini-programmation-o.../ComplementsCercleTest.java

96 lines
2.2 KiB
Java
Raw Normal View History

2023-06-20 19:03:42 +00:00
import org.junit.*;
import java.awt.Color;
import static org.junit.Assert.*;
/**
* Programme de test de la classe Cercle.
*/
public class ComplementsCercleTest {
public static final double EPSILON = 1e-6;
// précision pour la comparaison entre réels.
private Point p0 = new Point(0, 0);
private Point p1 = new Point(3, 4);
private Point p2 = new Point(-3, -4);
private Cercle c1;
private Cercle c2;
private Cercle c3;
private Cercle c4;
@Before
public void setUp() {
c1 = new Cercle(p0, 1);
c2 = new Cercle(p1, p2);
c3 = new Cercle(p1, p2, Color.MAGENTA);
c4 = Cercle.creerCercle(p0, p1);
}
@Test
public void testSetRayon() {
c1.setRayon(10);
assertEquals(10, c1.getRayon(), EPSILON);
assertEquals(20, c1.getDiametre(), EPSILON);
c2.setRayon(10);
assertEquals(10, c2.getRayon(), EPSILON);
assertEquals(20, c2.getDiametre(), EPSILON);
}
@Test
public void testSetDiametre() {
c1.setDiametre(20);
assertEquals(20, c1.getDiametre(), EPSILON);
assertEquals(10, c1.getRayon(), EPSILON);
c3.setDiametre(20);
assertEquals(20, c3.getDiametre(), EPSILON);
assertEquals(10, c3.getRayon(), EPSILON);
}
@Test
public void testSetCouleur() {
c1.setCouleur(Color.RED);
c3.setCouleur(Color.ORANGE);
assertEquals(Color.RED, c1.getCouleur());
assertEquals(Color.ORANGE, c3.getCouleur());
}
@Test
public void testSetCentre() {
c1.setCentre(new Point(10, 10));
assertEquals(10, c1.getCentre().getX(), EPSILON);
assertEquals(10, c1.getCentre().getY(), EPSILON);
}
@Test
public void testTranslater() {
c1.translater(100, 100);
assertEquals(100, c1.getCentre().getX(), EPSILON);
assertEquals(100, c1.getCentre().getY(), EPSILON);
c1.translater(-50, -150);
assertEquals( 50, c1.getCentre().getX(), EPSILON);
assertEquals(-50, c1.getCentre().getY(), EPSILON);
}
@Test
public void testContient() {
assertTrue(c4.contient(p0));
assertTrue(c4.contient(p1));
assertTrue(c4.contient(p2));
}
@Test
public void testPerimetre() {
assertEquals(2*Math.PI, c1.perimetre(), EPSILON);
assertEquals(10*Math.PI, c2.perimetre(), EPSILON);
}
@Test
public void testAire() {
assertEquals(Math.PI, c1.aire(), EPSILON);
assertEquals(25*Math.PI, c2.aire(), EPSILON);
}
}