package simpleMPI;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

import config.Example;
import edu.udel.cis.vsl.tass.config.VerifyConfiguration;
import edu.udel.cis.vsl.tass.front.minimp.ModelExtractor;
import edu.udel.cis.vsl.tass.model.IF.ModelIF;
import edu.udel.cis.vsl.tass.util.SyntaxException;
import edu.udel.cis.vsl.tass.verify.Verification;

public class SimpleMPITest {

	@Test
	public void simpleMPI() throws IOException, SyntaxException {
		ModelIF model;
		File rootDirectory = new File(Example.exampleDirectory, "simpleMPI");
		VerifyConfiguration verifyConfiguration = new VerifyConfiguration(
				new File(rootDirectory, "TASSREP"));

		verifyConfiguration.setSourceFile(new File(rootDirectory,
				"simpleMPI.c"));
		verifyConfiguration.setModelName("simpleMPI");
		verifyConfiguration.setNumProcs(2);
		verifyConfiguration.setVerbose(false);
		model = ModelExtractor.extractModel(verifyConfiguration);
		assertTrue(Verification.verify(model, verifyConfiguration, true));
	}
	
	@Test
	public void anysource() throws IOException, SyntaxException {
		ModelIF model;
		File rootDirectory = new File(Example.exampleDirectory, "simpleMPI");
		VerifyConfiguration verifyConfiguration = new VerifyConfiguration(
				new File(rootDirectory, "TASSREP"));

		verifyConfiguration.setSourceFile(new File(rootDirectory,
				"anysource.c"));
		verifyConfiguration.setModelName("anysource");
		verifyConfiguration.setNumProcs(4);
		verifyConfiguration.setVerbose(false);
		model = ModelExtractor.extractModel(verifyConfiguration);
		assertTrue(Verification.verify(model, verifyConfiguration, true));
	}
	
	@Test
	public void noInit() throws IOException, SyntaxException {
		ModelIF model;
		File rootDirectory = new File(Example.exampleDirectory, "simpleMPI");
		VerifyConfiguration verifyConfiguration = new VerifyConfiguration(
				new File(rootDirectory, "TASSREP"));

		verifyConfiguration.setSourceFile(new File(rootDirectory,
				"noInit.c"));
		verifyConfiguration.setModelName("noInit");
		verifyConfiguration.setNumProcs(3);
		verifyConfiguration.setVerbose(false);
		model = ModelExtractor.extractModel(verifyConfiguration);
		assertFalse(Verification.verify(model, verifyConfiguration, true));
	}
	
	@Test
	public void noFinalize() throws IOException, SyntaxException {
		ModelIF model;
		File rootDirectory = new File(Example.exampleDirectory, "simpleMPI");
		VerifyConfiguration verifyConfiguration = new VerifyConfiguration(
				new File(rootDirectory, "TASSREP"));

		verifyConfiguration.setSourceFile(new File(rootDirectory,
				"noFinalize.c"));
		verifyConfiguration.setModelName("noFinalize");
		verifyConfiguration.setNumProcs(3);
		verifyConfiguration.setVerbose(false);
		model = ModelExtractor.extractModel(verifyConfiguration);
		assertFalse(Verification.verify(model, verifyConfiguration, true));
	}
	
	@Test
	public void goodInitFinalize() throws IOException, SyntaxException {
		ModelIF model;
		File rootDirectory = new File(Example.exampleDirectory, "simpleMPI");
		VerifyConfiguration verifyConfiguration = new VerifyConfiguration(
				new File(rootDirectory, "TASSREP"));

		verifyConfiguration.setSourceFile(new File(rootDirectory,
				"goodInitFinalize.c"));
		verifyConfiguration.setModelName("goodInitFinalize");
		verifyConfiguration.setNumProcs(3);
		verifyConfiguration.setVerbose(false);
		model = ModelExtractor.extractModel(verifyConfiguration);
		assertTrue(Verification.verify(model, verifyConfiguration, true));
	}
	
	@Test
	public void count() throws IOException, SyntaxException {
		ModelIF model;
		File rootDirectory = new File(Example.exampleDirectory, "simpleMPI");
		VerifyConfiguration verifyConfiguration = new VerifyConfiguration(
				new File(rootDirectory, "TASSREP"));

		verifyConfiguration.setSourceFile(new File(rootDirectory,
				"count.c"));
		verifyConfiguration.setModelName("count");
		verifyConfiguration.setNumProcs(2);
		verifyConfiguration.setVerbose(false);
		model = ModelExtractor.extractModel(verifyConfiguration);
		assertTrue(Verification.verify(model, verifyConfiguration, true));
	}
	
	
}
