package edu.fiu.jtlex.data;

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Set;

import org.jacop.scala.node;
import org.junit.jupiter.api.Test;

public class InconsistencyDetectorTest {

	@Test
	void testConsistecyDetector0() {
		// Generate a graph with self loop inconsistency.
		IGraph TimeMLGraph = testUtils.generateTestGraph(0);
		Set<IGraph> subGraphs = InconsistencyDetector.generateInconsistentSubgraphs(TimeMLGraph);
		System.out.println("Sub Graphs...");
		if(subGraphs != null) {
			for (IGraph graph : subGraphs) {
				testUtils.printGraph(graph);
				System.out.println("Type: " + graph.getNodesCount());
				System.out.println("---------------------------");
			}
		}
	}

	@Test
	void testConsistecyDetector1() {
		// Generate a graph with self loop inconsistency.
		IGraph TimeMLGraph = testUtils.generateTestGraph(21);
		assertFalse(InconsistencyDetector.isConsistent(TimeMLGraph));
	}

	@Test
	void testConsistecyDetector2() {
		// Generate a graph with type 2-inconsistency.
		IGraph TimeMLGraph = testUtils.generateTestGraph(22);
		assertFalse(InconsistencyDetector.isConsistent(TimeMLGraph));
	}

	@Test
	void testConsistecyDetector3() {
		// Generate a graph with type 3-inconsistency.
		IGraph TimeMLGraph = testUtils.generateTestGraph(23);
		testUtils.printGraph(TimeMLGraph);
		assertFalse(InconsistencyDetector.isConsistent(TimeMLGraph));
	}

	@Test
	void testConsistecyDetector4() {
		// Generate a graph with no inconsistency.
		IGraph TimeMLGraph = testUtils.generateTestGraph(10);
		assertTrue(InconsistencyDetector.isConsistent(TimeMLGraph));
	}

	@Test
	void testConsistecyDetector5() {
		// Generate a graph with type 3-inconsistency.
		IGraph TimeMLGraph = testUtils.generateTestGraph(24);
		assertFalse(InconsistencyDetector.isConsistent(TimeMLGraph));
	}

	@Test
	void testGenerateInconsistentSubgraphs() {
		IGraph TimeMLGraph = testUtils.generateTestGraph(24);
		Set<IGraph> subGraphs = InconsistencyDetector.generateInconsistentSubgraphs(TimeMLGraph);
		System.out.println("Sub Graphs...");
		for (IGraph graph : subGraphs) {
			testUtils.printGraph(graph);
			System.out.println("---------------------------");
		}
	}

	@Test
	void testGenerateInconsistentSubgraphs2() {
		IGraph TimeMLGraph = testUtils.generateTestGraph(25);
		Set<IGraph> subGraphs = InconsistencyDetector.generateInconsistentSubgraphs(TimeMLGraph);
		System.out.println("Sub Graphs...");
		for (IGraph graph : subGraphs) {
			testUtils.printGraph(graph);
			System.out.println("---------------------------");
		}
	}
}
