Я делаю проект, у меня есть тестовый файл и интерфейс, и мне говорят сделать «линейный» файл, который успешно реализует интерфейс и проверяет успешность всех тестов. Он реализует и успешно на 3-х из 4-х тестов, но не на последнем, потому что она округляет по склону до 1,0 ...Bluej продолжает округлять мой двойной ... Как мне заставить его остановиться?
Вот код для тестера:
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class LineTest.
*
* @author (your name)
* @version (a version number or a date)
*/
public class LineTest
{
/**
* Default constructor for test class LineTest
*/
public LineTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
}
@Test
public void testConstructor()
{
Line line1 = new Line(10, 10, 25, 25);
assertEquals(10, line1.getXOne());
assertEquals(25, line1.getXTwo());
assertEquals(10, line1.getYOne());
assertEquals(25, line1.getYTwo());
}
@Test
public void testGetSlope()
{
Line line1 = new Line(10, 10, -25, -25);
assertEquals(0.0, line1.getSlope(), 0.1);
line1.print();
}
@Test
public void testCalcSlope()
{
Line line1 = new Line(10, 10, -25, -25);
line1.calculateSlope();
assertEquals(1.0, line1.getSlope(), 0.1);
line1.print();
}
@Test
public void testSetCoords()
{
Line line1 = new Line(10, 10, -25, -35);
line1.calculateSlope();
assertEquals(1.285, line1.getSlope(), 0.003);
line1.print();
line1.setCoordinates(10, 10, 25, 35);
line1.calculateSlope();
assertEquals(1.667, line1.getSlope(), 0.001);
line1.print();
}
}
Вот строка класс:
public class Line
{
private int xOne,yOne, xTwo, yTwo;
private double slope;
public Line(int x1, int y1, int x2, int y2)
{
xOne=x1;
yOne=y1;
xTwo=x2;
yTwo=y2;
}
public void setCoordinates(int x1, int y1, int x2, int y2)
{
x1=xOne;
y1=yOne;
x2=xTwo;
y2=yTwo;
}
public void calculateSlope()
{
slope = (((yTwo)-(yOne))/((xTwo)-(xOne)));
}
public void print()
{
System.out.println("The slope of the line created by the points ("+xOne+","+yOne+"), and ("+xTwo+","+yTwo+") is "+slope+".");
}
public int getXOne(){
return xOne;
}
public int getXTwo(){
return xTwo;
}
public int getYOne(){
return yOne;
}
public int getYTwo(){
return yTwo;
}
public double getSlope(){
return slope;
}
}
Вот интерфейс:
public interface TestableLine
{
public void setCoordinates(int x1, int y1, int x2, int y2);
public void calculateSlope();
public void print();
public int getXOne();
public int getYOne();
public int getXTwo();
public int getYTwo();
public double getSlope();
}
Что случилось Вот? Я попытался указать число десятичных знаков, чтобы округлить, это просто делает тест 3 неудачным.
Так ответ ответил? – Fortunato
Да, как я сказал в своих нижних комментариях, но что-то не так с моим методом setcoords в фактическом классе строк. Он не читает его, видимо, поэтому он все еще видит координаты как 10,10, -25, -35, а не то, что ДОЛЖЕН быть там после 'line1.setCoordinates (10,10,25,35);' – BMK600