import java.io.IOException;

import org.junit.Test;
import org.polymodel.x10p.Program;
import org.polymodel.x10p.X10pParser;
import org.polymodel.x10p.analysis.HappensBefore;
import org.polymodel.x10p.util.X10pUnparser;


public class HappensBeforeTest {


	private static final String ROOT = "./x10src/";
	
	@Test
	public void example1() {
		test("example1.x10p", new String[][]{
				new String[]{"S0", "S1"},
				new String[]{"S1", "S0"},
		});
	}
	

	@Test
	public void ex60() {
		test("ex60.x10p", new String[][]{
				new String[]{"Z", "Q"},
				new String[]{"Q", "MAC"},
				new String[]{"Q", "Z"},
				new String[]{"MAC", "Z"},
		});
	}
	
	private void test(String file, String[][] hbChecks) {
		System.out.println(file +":\n");
		try {
			Program prog = X10pParser.loadModel(ROOT+file);
			System.out.println(X10pUnparser.unparseWithTimeStamps(prog));
			for (String[] check : hbChecks) {
				System.out.print(check[0] + " < " + check[1] + ": ");
				System.out.println(HappensBefore.check(prog, check[0], check[1]));
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
