package laplace;

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.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;

public class Laplace2Test {
	private static ModelIF specModel, implModel;
	private static CompareConfiguration compareConfiguration;

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

		compareConfiguration = new CompareConfiguration(new File(rootDirectory,
				"TASSREP"));
		compareConfiguration.setSpecSourceFile(new File(rootDirectory,
				"laplaceSpec.c"));
		compareConfiguration.setImplSourceFile(new File(rootDirectory,
				"laplaceImpl.c"));
		compareConfiguration.setInput("NX_BOUND", 4);
		compareConfiguration.setInput("NY_BOUND", 6);
		compareConfiguration.setInput("TIME_BOUND", 3);
		compareConfiguration.setSpecNumProcs(1);
		compareConfiguration.setImplNumProcs(3);
		compareConfiguration.setSpecModelName("laplaceSpec");
		compareConfiguration.setImplModelName("laplaceImpl");
		pair = ModelExtractor.extractModelPair(compareConfiguration);
		specModel = pair.spec();
		implModel = pair.impl();
	}

	@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 testComparePotentialUrgent() throws FileNotFoundException {
		CompareConfiguration config = new CompareConfiguration(
				compareConfiguration);

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

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

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