package skewFactor;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileNotFoundException;

import org.junit.BeforeClass;
import org.junit.Test;

import config.Example;
import edu.udel.cis.vsl.tass.config.CompareConfiguration;
import edu.udel.cis.vsl.tass.config.VerifyConfiguration;
import edu.udel.cis.vsl.tass.config.RunConfiguration.DeadlockStrategy;
import edu.udel.cis.vsl.tass.config.RunConfiguration.ReductionStrategy;
import edu.udel.cis.vsl.tass.front.minimp.ModelExtractor;
import edu.udel.cis.vsl.tass.front.minimp.ModelPair;
import edu.udel.cis.vsl.tass.model.IF.ModelIF;
import edu.udel.cis.vsl.tass.verify.Comparison;
import edu.udel.cis.vsl.tass.verify.Verification;

public class SkewFactorTest {

	private static ModelIF specModel, implModel;
	private static CompareConfiguration compareConfiguration;
	private static VerifyConfiguration specConfiguration, implConfiguration;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ModelPair pair;
		File rootDirectory = new File(Example.exampleDirectory, "skewFactor");

		compareConfiguration = new CompareConfiguration(new File(rootDirectory,
				"TASSREP"));
		compareConfiguration.setSimplify(false);
		
		compareConfiguration.setSpecSourceFile(new File(rootDirectory,
				"skewFactorSpec.c"));
		compareConfiguration.setImplSourceFile(new File(rootDirectory,
				"skewFactorImpl.c"));
		compareConfiguration.setInput("N_BOUND", 4);
		compareConfiguration.setSpecNumProcs(1);
		compareConfiguration.setImplNumProcs(1);
		compareConfiguration.setSpecModelName("skewFactorSpec_4");
		compareConfiguration.setImplModelName("skewFactorImpl_4");
		specConfiguration = compareConfiguration.specConfiguration();
		implConfiguration = compareConfiguration.implConfiguration();
		pair = ModelExtractor.extractModelPair(compareConfiguration);
		specModel = pair.spec();
		implModel = pair.impl();
	}

	@Test
	public void testVerifySpec() throws FileNotFoundException {
		assertTrue(Verification.verify(specModel, specConfiguration, true));
	}

	@Test
	public void testVerifyImpl() throws FileNotFoundException {
		assertTrue(Verification.verify(implModel, implConfiguration, true));
	}

	@Test
	public void testVerifyImplUrgent() throws FileNotFoundException {
		VerifyConfiguration config = new VerifyConfiguration(implConfiguration);

		config.setReductionStrategy(ReductionStrategy.URGENT);
		assertTrue(Verification.verify(implModel, config, true));
	}

	@Test
	public void testVerifyImplSimplify() throws FileNotFoundException {
		VerifyConfiguration config = new VerifyConfiguration(implConfiguration);

		config.setSimplify(true);
		assertTrue(Verification.verify(implModel, config, true));
	}

	@Test
	public void testVerifyImplSimplifyUrgent() throws FileNotFoundException {
		VerifyConfiguration config = new VerifyConfiguration(implConfiguration);

		config.setSimplify(true);
		config.setReductionStrategy(ReductionStrategy.URGENT);
		assertTrue(Verification.verify(implModel, config, true));
	}

	@Test
	public void testCompare() throws FileNotFoundException {
		assertTrue(Comparison.compare(specModel, implModel,
				compareConfiguration, true));
	}

	@Test
	public void testCompareUrgent() throws FileNotFoundException {
		CompareConfiguration config = new CompareConfiguration(
				compareConfiguration);

		config.setReductionStrategy(ReductionStrategy.URGENT);
		assertTrue(Comparison.compare(specModel, implModel, config, true));
	}

	@Test
	public void testComparePotential() throws FileNotFoundException {
		CompareConfiguration config = new CompareConfiguration(
				compareConfiguration);

		config.setDeadlockStrategy(DeadlockStrategy.POTENTIAL);
		assertTrue(Comparison.compare(specModel, implModel, config, true));
	}

	@Test
	public void testComparePotentialSimplify() throws FileNotFoundException {
		CompareConfiguration config = new CompareConfiguration(
				compareConfiguration);

		config.setDeadlockStrategy(DeadlockStrategy.POTENTIAL);
		config.setSimplify(true);
		assertTrue(Comparison.compare(specModel, implModel, config, true));
	}

	@Test
	public void testCompareIgnore() throws FileNotFoundException {
		CompareConfiguration config = new CompareConfiguration(
				compareConfiguration);

		config.setDeadlockStrategy(DeadlockStrategy.IGNORE);
		assertTrue(Comparison.compare(specModel, implModel, config, true));
	}
}
