algorithms-for-computing-li.../LinearRegressionTool/src/test/java/de/wwwu/awolf/presenter/algorithms/advanced/LeastMedianOfSquaresEstimat...

65 lines
1.7 KiB
Java

package de.wwwu.awolf.presenter.algorithms.advanced;
import de.wwwu.awolf.model.Line;
import de.wwwu.awolf.presenter.algorithms.Algorithm;
import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler;
import org.junit.Before;
import org.junit.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
/**
* 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 Set<Line> lines;
private Line line;
@Before
public void setUp(){
Double[] x = {18d, 24d, 30d, 34d, 38d};
Double[] y = {18d, 26d, 30d, 40d, 70d};
lines = new HashSet<>();
for (int i = 0; i < 5; i++) {
lines.add(new Line(x[i], y[i]));
}
line = AlgorithmHandler.getInstance().runAlgorithmByType(Algorithm.Type.LMS, lines);
}
@Test
public void geEjValues() throws Exception {
Double[] expected = {36d, 50d, 60d, 74d, 108d};
List<Double> actual = lms.getEjValues(1d);
assertArrayEquals(expected, actual.toArray());
}
@Test
public void upperBound() throws Exception {
Line expected = new Line(5, 5, 146, 210);
assertEquals(expected.getX1(), line.getX1(), 0.01);
assertEquals(expected.getX2(), line.getX2(), 0.01);
assertEquals(expected.getY1(), line.getY1(), 0.01);
assertEquals(expected.getY2(), line.getY2(), 0.01);
}
}