93 lines
2.6 KiB
Java
93 lines
2.6 KiB
Java
package presenter.algorithms.advanced;
|
|
|
|
import model.Interval;
|
|
import model.Line;
|
|
import model.Point;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import presenter.util.IntersectionComputer;
|
|
import presenter.util.IntersectionCounter;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedList;
|
|
|
|
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 LeastMedianOfSquaresEstimatorTest {
|
|
|
|
private LeastMedianOfSquaresEstimator lms;
|
|
private IntersectionComputer intersectionComputer;
|
|
|
|
@Before
|
|
public void setUp(){
|
|
Double[] x = {18d, 24d, 30d, 34d, 38d};
|
|
Double[] y = {18d, 26d, 30d, 40d, 70d};
|
|
|
|
|
|
LinkedList<Line> lines = new LinkedList<>();
|
|
ArrayList<Point> 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();
|
|
lms = new LeastMedianOfSquaresEstimator(lines, intersections);
|
|
}
|
|
|
|
|
|
@Test
|
|
public void geEjValues() throws Exception {
|
|
|
|
Double[] expected = {36d, 50d, 60d, 74d, 108d};
|
|
ArrayList<Double> actual = lms.getEjValues(1d);
|
|
assertArrayEquals(expected, actual.toArray());
|
|
}
|
|
|
|
@Test
|
|
public void calcKMinusBracelet() throws Exception {
|
|
|
|
Point point = new Point(1d, 1d);
|
|
Double[] expected = {24d, 36d, 60d};
|
|
Double[] actual = lms.calcKMinusBracelet(point, 3);
|
|
|
|
assertArrayEquals(expected, actual);
|
|
|
|
}
|
|
|
|
@Test
|
|
public void upperBound() throws Exception {
|
|
lms.setkMinus(3);
|
|
lms.setHeightsigmaMin(500);
|
|
lms.setSigmaMin(new Line(0, 0, 0, 0));
|
|
lms.setN(5);
|
|
Line expected = new Line(5, 5, 146, 210);
|
|
lms.upperBound(5d);
|
|
|
|
assertEquals(expected.getX1(), lms.getSigmaMin().getX1(), 0.01);
|
|
assertEquals(expected.getX2(), lms.getSigmaMin().getX2(), 0.01);
|
|
assertEquals(expected.getY1(), lms.getSigmaMin().getY1(), 0.01);
|
|
assertEquals(expected.getY2(), lms.getSigmaMin().getY2(), 0.01);
|
|
}
|
|
|
|
@Test
|
|
public void lowerBound() throws Exception {
|
|
//kann nur über sout geprüft werden test passt aber
|
|
Double[] expectedAlpha = {0d, 0d, 0d, 2d, 4d};
|
|
Double[] expectedBeta = {2d, 4d, 4d, 2d, 1d};
|
|
lms.setHeightsigmaMin(500);
|
|
|
|
Interval interval = new Interval(-2, 0);
|
|
lms.lowerBound(interval);
|
|
assertTrue(interval.getActivity());
|
|
}
|
|
|
|
} |