algorithms-for-computing-li.../LinearRegressionTool/src/test/java/presenter/util/IntersectionComputerTest.java

58 lines
1.5 KiB
Java

package presenter.util;
import model.Line;
import model.LineModel;
import model.Point;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.Assert.*;
/**
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
*
* @Author: Armin Wolf
* @Email: a_wolf28@uni-muenster.de
* @Date: 23.10.2017.
*/
public class IntersectionComputerTest {
private IntersectionComputer intersectionComputer;
private LineModel lineModel;
@Before
public void setUp() throws Exception {
lineModel = new LineModel();
lineModel.addLine(new Line(3,13,10,3));
lineModel.addLine(new Line(1,9,1,9));
lineModel.addLine(new Line(1,12,4,6));
intersectionComputer = new IntersectionComputer(lineModel.getLines());
}
@Test
public void compute() throws Exception {
ArrayList<Point> intersections = intersectionComputer.compute();
double[] expectedX = {4.66, 7.11, 9.39};
double[] expectedY = {4.66, 7.11, 5.52};
double[] actualX = new double[3];
double[] actualY = new double[3];
for (int i=0;i<3;i++){
actualX[i] = intersections.get(i).getX();
actualY[i] = intersections.get(i).getY();
}
Arrays.sort(expectedX);
Arrays.sort(actualX);
assertArrayEquals(expectedX, actualX, 0.01d);
Arrays.sort(expectedY);
Arrays.sort(actualY);
assertArrayEquals(expectedY, actualY, 0.01d);
}
}