package com.approximatrix.draco.datamodel;

import static org.junit.Assert.*;

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

public class VariableModelTest {
	
	private static final double[] data = {-1.0,2.0,-3.0,4.0,-5.0,6.0,1.0};
	
	VariableModel var = null;
	
	@Before
	public void setUp() throws Exception {
		var = new VariableModel("var",data);
	}

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

	@Test
	public void testGetMaximumValue() {
		assertEquals(6.0,var.getMaximumValue());
	}

	@Test
	public void testGetMinimumValue() {
		assertEquals(-5.0,var.getMinimumValue());
	}

	@Test
	public void testGetMean() {
		assertEquals(0.57142857142857,var.getMean());
	}

	@Test
	public void testGetMedian() {
		assertEquals(1.0,var.getMedian());
	}

	@Test
	public void testGetColumnStandardDeviation() {
		assertCloseTo(3.86683086679272,var.getColumnStandardDeviation());
	}

	protected void assertCloseTo(double expected, double actual) {
		assertTrue(expected+1.0E-8/2.0 > actual);
		assertTrue(expected-1.0E-8/2.0 < actual);
	}
	
}
