package de.wwwu.awolf.presenter.algorithms.advanced; import de.wwwu.awolf.model.Line; import de.wwwu.awolf.model.Point; import org.junit.Before; import org.junit.Test; import de.wwwu.awolf.presenter.util.IntersectionComputer; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; 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 TheilSenEstimatorTest { TheilSenEstimator estimator; IntersectionComputer intersectionComputer; @Before public void setUp(){ Double[] x = {18d, 24d, 30d, 34d, 38d}; Double[] y = {18d, 26d, 30d, 40d, 70d}; List lines = new LinkedList<>(); List intersections = new ArrayList<>(); for (int i = 0; i < 5; i++) { lines.add(new Line(x[i], y[i])); } intersectionComputer = new IntersectionComputer(lines); intersections = intersectionComputer.compute(); estimator = new TheilSenEstimator(lines, intersections); } @Test public void getIntervalSize() throws Exception { assertEquals(estimator.getIntervalSize(-2d, 0d), 5, 0.001); } @Test public void getOpenIntervalSize() throws Exception { assertEquals(estimator.getIntervalSize(-1.4d, 0.6666d), 4, 0.001); } @Test public void getOpenIntervalElements() throws Exception { List intersectionInInterval = estimator.getOpenIntervalElements(-1.4d, -0.67d); double[] expected = {-1.375, -1.333, -1.0}; double[] actual = new double[3]; for (int i=0;i