package test;

import static org.junit.Assert.*;

import misc.PolyFunction;

import org.junit.Test;

import finders.InvalidFuncException;
import finders.LinearFinder;
import finders.NewtonFinder;
import finders.QuadraticFinder;

public class FrameworkTest {
	// empty koeffs should be 0
	@Test public void testPolyFunctionEmptyKoeff() {
		PolyFunction f = new PolyFunction().
			setKoeff(7.0,	2).
			setKoeff(5.0,	0);
		
		assertEquals((Double) 0.0, f.getKoeff(1));
	}
	
	// do not accept bad PolyFunctions 
	@Test public void testFinderInvalidFunc() {
		PolyFunction f1 = new PolyFunction();
		try {
			new LinearFinder().find(f1);
			fail();
		} catch (InvalidFuncException e) {
			// success
		}
		try {
			new QuadraticFinder().find(f1);
			fail();
		} catch (InvalidFuncException e) {
			// success
		}
		try {
			new NewtonFinder().find(f1);
			fail();
		} catch (InvalidFuncException e) {
			// success
		}
	}
	
	// text maxGrade
	@Test public void testPolyFunctionMaxGrade() {
		PolyFunction f1 = new PolyFunction()
			.setKoeff(1.0, 4);
		assertEquals(4, f1.getMaxGrade());
		
		PolyFunction f2 = new PolyFunction()
			.setKoeff(1.0, 4)
			.setKoeff(1.0, 2);
		assertEquals(4, f2.getMaxGrade());
		
		PolyFunction f3 = new PolyFunction()
			.setKoeff(1.0, 2);
		assertEquals(2, f3.getMaxGrade());
		
		// set a koeff to 0
		PolyFunction f4 = new PolyFunction()
			.setKoeff(1.0, 1)
			.setKoeff(1.0, 2)
			.setKoeff(0.0, 2);
		assertEquals(1, f4.getMaxGrade());
	}
}

@@ -503,16 +503,54 @@
 ions
- 
 %0A%09@Test
+(expected = InvalidFuncException.class)
  pub
@@ -562,16 +562,22 @@
 oid test
+Linear
 FinderIn
@@ -630,25 +630,16 @@
 tion();%0A
-%09%09try %7B%0A%09
 %09%09new Li
@@ -666,287 +666,340 @@
 );%0A%09
-%09%09fail();%0A%09%09%7D catch (InvalidFuncException e) %7B%0A%09%09%09// success%0A%09%09%7D%0A%09%09try %7B%0A%09%09%09new QuadraticFinder().find(f1);%0A%09%09%09fail();%0A%09%09%7D catch (InvalidFuncException e) %7B%0A%09%09%09// success%0A%09%09%7D%0A%09%09try %7B%0A%09%09%09new NewtonFinder().find(f1);%0A%09%09%09fail();%0A%09%09%7D catch (InvalidFuncException e) %7B%0A%09%09%09// success%0A%09%09%7D
+%7D%0A%09@Test(expected = InvalidFuncException.class) public void testQuadraticFinderInvalidFunc() %7B%0A%09%09PolyFunction f1 = new PolyFunction();%0A%09%09new QuadraticFinder().find(f1);%0A%09%7D%0A%09@Test(expected = InvalidFuncException.class) public void testNewtonFinderInvalidFunc() %7B%0A%09%09PolyFunction f1 = new PolyFunction();%0A%09%09new NewtonFinder().find(f1);
 %0A%09%7D%0A

refactor FrameworkTest to stop using try/catch