projet-mini-programmation-o.../CercleTest.java
2023-06-20 21:03:42 +02:00

106 lines
3 KiB
Java

import org.junit.*;
import java.awt.Color;
import static org.junit.Assert.*;
/**
* Programme de test de la classe Cercle.
*/
public class CercleTest {
public static final double EPSILON = 1e-6;
// précision pour la comparaison entre réels.
/** Vérifier si deux points ont mêmes coordonnées.
* @param p1 le premier point
* @param p2 le deuxième point
*/
static void memesCoordonnees(Point p1, Point p2) {
assertEquals(p1.getX(), p2.getX(), EPSILON);
assertEquals(p1.getY(), p2.getY(), EPSILON);
}
private Point p_0 = new Point(0, 0);
private Point p_pp = new Point(3, 4);
private Point p_pm = new Point(3, -4);
private Point p_mm = new Point(-3, -4);
private Point p_mp = new Point(-3, 4);
private Cercle[] c12a = {new Cercle(p_pp, p_mm),
new Cercle(p_pm, p_mp),
new Cercle(p_mp, p_pm),
new Cercle(p_mm, p_pp)};
private Cercle[] c12b = {new Cercle(p_pp, p_pm),
new Cercle(p_pm, p_mm),
new Cercle(p_mm, p_mp),
new Cercle(p_mp, p_pp)};
private Cercle[] c13 = {new Cercle(p_pp, p_mm, Color.RED),
new Cercle(p_pm, p_mp, Color.GREEN),
new Cercle(p_mp, p_pm, Color.WHITE),
new Cercle(p_mm, p_pp, Color.BLACK)};
private Cercle[] c14 = {Cercle.creerCercle(p_0, p_pp),
Cercle.creerCercle(p_0, p_pm),
Cercle.creerCercle(p_0, p_mp),
Cercle.creerCercle(p_0, p_mm)};
@Test
public void testE12a() {
for (Cercle c : c12a) {
assertNotNull(c);
assertEquals(5, c.getRayon(), EPSILON);
assertEquals(10, c.getDiametre(), EPSILON);
memesCoordonnees(p_0, c.getCentre());
assertTrue(c.getCouleur() == Color.BLUE);
}
}
@Test
public void testE12b() {
for (Cercle c : c12b) {
assertNotNull(c);
assertTrue(c.getCouleur() == Color.BLUE);
}
assertEquals(4, c12b[0].getRayon(), EPSILON);
assertEquals(8, c12b[0].getDiametre(), EPSILON);
assertEquals(3, c12b[1].getRayon(), EPSILON);
assertEquals(6, c12b[1].getDiametre(), EPSILON);
assertEquals(4, c12b[2].getRayon(), EPSILON);
assertEquals(8, c12b[2].getDiametre(), EPSILON);
assertEquals(3, c12b[3].getRayon(), EPSILON);
assertEquals(6, c12b[3].getDiametre(), EPSILON);
memesCoordonnees(new Point(3, 0), c12b[0].getCentre());
memesCoordonnees(new Point(0, -4), c12b[1].getCentre());
memesCoordonnees(new Point(-3, 0), c12b[2].getCentre());
memesCoordonnees(new Point(0, 4), c12b[3].getCentre());
}
@Test
public void testE13() {
for (Cercle c : c13) {
assertNotNull(c);
assertEquals(5, c.getRayon(), EPSILON);
assertEquals(10, c.getDiametre(), EPSILON);
memesCoordonnees(p_0, c.getCentre());
}
assertTrue(c13[0].getCouleur() == Color.RED);
assertTrue(c13[1].getCouleur() == Color.GREEN);
assertTrue(c13[2].getCouleur() == Color.WHITE);
assertTrue(c13[3].getCouleur() == Color.BLACK);
}
@Test
public void testE14() {
for (Cercle c : c14) {
assertNotNull(c);
assertEquals(5, c.getRayon(), EPSILON);
assertEquals(10, c.getDiametre(), EPSILON);
memesCoordonnees(p_0, c.getCentre());
assertTrue(c.getCouleur() == Color.BLUE);
}
}
}