Triangulo
package figura.triangulo;
public class Triangulo {
double base; double altura;
public Triangulo(double dato1){
base = dato1; altura = ((Math.sqrt(3))/2)*(base);
}
public double area(){
return (base * altura)/2;
}
public double perimetro(){
return (base*3);
}
public double obtenerBase(){
return base;
}
public void modificarBase(double dato1){
base=dato1;
}
public double obtenerAltura(){
return altura;
}
}
package Pruebas;
import figura.triangulo.TrianguloEquilatero;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class TrianguloTest {
static TrianguloEquilatero triangulo;
public TrianguloTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
triangulo = new TrianguloEquilatero(4.0);
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
// @Test
// public void hello() {}
@Test public void areaTest(){
assertEquals(triangulo.area(),6.928203230275509,0);
}
@Test public void perimetroTest(){
assertEquals(triangulo.perimetro(),12,0);
}
@Test public void obtenerLadosTest(){
assertEquals(triangulo.obtenerBase(),4,5);
assertEquals(triangulo.obtenerAltura(),3.4641016151377544,0);
}
@Test public void modificarLadosTest(){
triangulo.modificarBase(7.0);
assertEquals(triangulo.obtenerBase(),7,0);
}
@Test public void nuevoTest(){
System.out.println(triangulo.obtenerBase());
}
}
No hay comentarios:
Publicar un comentario