package com.approximatrix.draco.fit.functions;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ProbitLikelihoodTest {

	private ProbitLikelihood pl = null;
	
	@Before
	public void setUp() throws Exception {
		pl = new ProbitLikelihood();
	}

	@After
	public void tearDown() throws Exception {
		pl = null;
	}

	@Test
	public void testEvaluatePDF() {
		double[] parameters = {1.0,1.0};
		double[] variables = {0.0};
		double value = pl.evaluatePDF(parameters, variables);
		assertWithin(0.24197,value,0.0001);
	}

	@Test
	public void testEvaluateFunction() {
		double[] parameters = {1.0,1.0};
		double[] variables = {0.0};
		double value = pl.evaluateFunction(parameters, variables);
		assertWithin(0.84134,value,0.0001);
	}
	
	private void assertWithin(double expected, double actual, double delta) {
		if(delta < 0.0)
			throw new IllegalArgumentException();
		
		assertTrue(expected > actual - delta);
		assertTrue(expected < actual + delta);
	}

}
