algorithms-for-computing-li.../LinearRegressionTool/src/test/java/de/wwwu/awolf/presenter/util/IntersectionCounterTest.java

63 lines
1.7 KiB
Java

package de.wwwu.awolf.presenter.util;
import de.wwwu.awolf.model.Interval;
import de.wwwu.awolf.model.Line;
import de.wwwu.awolf.model.LineModel;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
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 IntersectionCounterTest {
private IntersectionCounter intersectionCounter;
private LineModel lineModel;
@Before
public void setUp() throws Exception {
intersectionCounter = new IntersectionCounter();
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));
for (Line l :lineModel.getLines()) {
System.out.println("Steigung: "+l.getM()+"\t y-Achsenabschnitt: "+l.getB());
}
}
@Test
public void run() throws Exception {
assertEquals(3, intersectionCounter.run(lineModel.getLines(), new Interval(-9999,9999)));
}
@Test
public void testInversionInLists(){
// double[] umin = {6,3,4,1,2,5};
// double[] umax = {3,5,2,6,1,4};
double[] umin = {1, 2, 3, 4};
double[] umax = {2, 3, 4, 1};
ArrayList<Integer> a = new ArrayList<>();
ArrayList<Integer> b = new ArrayList<>();
for (double d : umin) {
a.add((int) d);
}
for (double d : umax) {
b.add((int) d);
}
IntersectionCounter invCounter = new IntersectionCounter();
int ret = invCounter.run(a, b);
assertEquals(3d, ret, 0.001);
}
}