package test;

import static org.junit.Assert.*;

import java.util.Vector;

import misc.PolyFunction;

import org.junit.Test;

import finders.FinderInterface;
import finders.InvalidFuncException;
import finders.LinearFinder;
import finders.QuadricFinder;

public class FinderTest {
	@Test public void testLinearFinder() {
		FinderInterface finder = new LinearFinder();
		
		// -2/3x + 5
		// result = 7.5
		PolyFunction f1 = new PolyFunction().
			setKoeff(0, 5.0).
			setKoeff(1, -2.0/3.0);
		try {
			assertEquals((Double) 7.5, finder.find(f1).firstElement());
		} catch (InvalidFuncException e) {
			fail();
		}
	}
	
	@Test public void testQuadricFinder() {
		FinderInterface finder = new QuadricFinder();
		
		// 1/2x^2 - 2x - 6
		// results = -2.0, 6.0
		PolyFunction f1 = new PolyFunction().
			setKoeff(0, -6.0).
			setKoeff(1, -2.0).
			setKoeff(2, 0.5);
		try {
			Vector<Double> results = finder.find(f1);
			assertTrue(results.contains(-2.0));
			assertTrue(results.contains(6.0));
		} catch (InvalidFuncException e) {
			fail();
		}
	}
}

@@ -218,16 +218,51 @@
 Finder;%0A
+import finders.NewtonFinderGrade3;%0A
 import f
@@ -283,16 +283,16 @@
 Finder;%0A
-
 %0Apublic 
@@ -396,24 +396,44 @@
 inder();%0A%09%09%0A
+%09%09// probeprfung 2a%0A
 %09%09// -2/3x +
@@ -756,24 +756,44 @@
 inder();%0A%09%09%0A
+%09%09// probeprfung 2b%0A
 %09%09// 1/2x%5E2 
@@ -822,15 +822,11 @@
 = -2
-.0
 , 6
-.0
 %0A%09%09P
@@ -1019,16 +1019,16 @@
 -2.0));%0A
-
 %09%09%09asser
@@ -1112,10 +1112,489 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09@Test public void testNewtonFinderGrade3() %7B%0A%09%09FinderInterface finder = new NewtonFinderGrade3();%0A%09%09%0A%09%09// probeprfung 2e%0A%09%09// x%5E3 - 3x - 2%0A%09%09// results = -1, 2%0A%09%09PolyFunction f1 = new PolyFunction().%0A%09%09%09setKoeff(0, -2.0).%0A%09%09%09setKoeff(1, -3.0).%0A%09%09%09setKoeff(3, 1.0);%0A%09%09System.out.println(f1);%0A%09%09try %7B%0A%09%09%09Vector%3CDouble%3E results = finder.find(f1);%0A%09%09%09assertTrue(results.contains(-1.0));%0A%09%09%09assertTrue(results.contains(2.0));%0A%09%09%7D catch (InvalidFuncException e) %7B%0A%09%09%09fail();%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

add a newton test