package diffusion;

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 Diffusion_3_1_2_Test {

	private static ModelIF specModel, implModel;
	private static CompareConfiguration compareConfiguration;
	private static VerifyConfiguration specConfiguration, implConfiguration;
	private static int nprocs = 2;

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

		compareConfiguration = new CompareConfiguration(new File(rootDirectory,
				"TASSREP"));
		compareConfiguration.setReductionStrategy(ReductionStrategy.URGENT);
		compareConfiguration.setDeadlockStrategy(DeadlockStrategy.IGNORE);
		compareConfiguration.setSpecSourceFile(new File(rootDirectory,
				"diffusion_seq.c"));
		compareConfiguration.setImplSourceFile(new File(rootDirectory,
				"diffusion_par.c"));
		compareConfiguration.setInput("NX_BOUND", 3);
		compareConfiguration.setInput("NSTEPS_BOUND", 1);
		compareConfiguration.setSpecNumProcs(1);
		compareConfiguration.setImplNumProcs(nprocs);
		compareConfiguration.setSpecModelName("diffusion_seq_3_1");
		compareConfiguration.setImplModelName("diffusion_par_3_1");
		specConfiguration = compareConfiguration.specConfiguration();
		implConfiguration = compareConfiguration.implConfiguration();
		implConfiguration.setDeadlockStrategy(DeadlockStrategy.POTENTIAL);		
		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 testVerifyImplIgnore() throws FileNotFoundException {
		VerifyConfiguration config = new VerifyConfiguration(implConfiguration);

		config.setDeadlockStrategy(DeadlockStrategy.IGNORE);
		assertTrue(Verification.verify(implModel, config, true));
	}

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

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