package com.approximatrix.draco.fit;

import static org.junit.Assert.assertTrue;

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

import com.approximatrix.draco.datamodel.StatTableModel;
import com.approximatrix.draco.io.sql.DracoSQLRead;

public abstract class RegressionTestSkeleton {
	
	protected static final String NORRIS_FILE = "resources/norris.sql-draco";
	protected static final String NOINT1_FILE = "resources/noint1.sql-draco";
	protected static final String NOINT2_FILE = "resources/noint2.sql-draco";
	protected static final String WAMPLER1_FILE = "resources/wampler1.sql-draco";
	protected static final String PONTIUS_FILE = "resources/pontius.sql-draco";
	protected static final String MISRA1A_FILE = "resources/misra1a.sql-draco";
	
	protected static final double DELTA = 1.0E-9;
	
	StatTableModel norris = null;
	StatTableModel noint1 = null;
	StatTableModel noint2 = null;
	StatTableModel wampler1 = null;
	StatTableModel pontius = null;
	StatTableModel misra1a = null;
	
	@Before
	public void setUp() throws Exception {
		norris = loadModel(NORRIS_FILE);
		noint1 = loadModel(NOINT1_FILE);
		noint2 = loadModel(NOINT2_FILE);
		wampler1 = loadModel(WAMPLER1_FILE);
		pontius = loadModel(PONTIUS_FILE);
		misra1a = loadModel(MISRA1A_FILE);
	}

	@After
	public void tearDown() throws Exception {
		norris = null;
		noint1 = null;
		noint2 = null;
		wampler1 = null;
		pontius = null;
		misra1a = null;
	}
	
	protected StatTableModel loadModel(String filename) {
		DracoSQLRead reader = new DracoSQLRead(filename);
		StatTableModel ret = reader.loadModel();
		reader.close();
		return ret;
	}
	
	protected void assertCloseTo(double expected, double actual, double delta) {
		assertTrue(expected+delta/2.0 > actual);
		assertTrue(expected-delta/2.0 < actual);
	}
}
