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.NewtonFinder;
import finders.QuadricFinder;

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

@@ -1147,14 +1147,9 @@
 nder
-Grade3
+1
 () %7B
@@ -1451,24 +1451,24 @@
 ins(-1.0));%0A
-
 %09%09%09assertTru
@@ -1548,10 +1548,388 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09@Test public void testNewtonFinder2() %7B%0A%09%09FinderInterface finder = new NewtonFinder();%0A%09%09%0A%09%09// x%5E3%0A%09%09// result = 0%0A%09%09PolyFunction f1 = new PolyFunction().%0A%09%09%09setKoeff(3, 1.0);%0A%09%09try %7B%0A%09%09%09Vector%3CDouble%3E results = finder.find(f1);%0A%09%09%09assertEquals(1, results.size());%0A%09%09%09assertEquals((Double) 0.0, results.firstElement());%0A%09%09%7D catch (InvalidFuncException e) %7B%0A%09%09%09fail();%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

add test case for newton with 1 result