package EC;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.ArrayList;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import Liste.ListeChainee;
import Liste.ListeChaineeImpl;
import Liste.MyList;
import Liste.MyListImpl;

public class build_EC
{
	private static ArrayList<String> OP;
	private static ArrayList<ArrayList<Object>> V;
	
	// Temp values for the tests
	MyList list;
	ListeChainee suiteChainee;
	ArrayList<Object> result;

	@BeforeClass
	public static void testSetup() 
	{
		OP = new ArrayList<String>();
		OP.add("union");
		OP.add("intersection");
		OP.add("difference");
		OP.add("symDifference");
		OP.add("isSubset");
		OP.add("isSuperset");
		
		ArrayList<Object> tmp;
		V = new ArrayList<ArrayList<Object>>();
		
		// Empty set
		tmp = new ArrayList<Object>();
		V.add(tmp);
		
		// {1}
		tmp = new ArrayList<Object>();
		tmp.add(1);
		V.add(tmp);
		
		// {5}
		tmp = new ArrayList<Object>();
		tmp.add(5);
		V.add(tmp);
		
		// {1,2,3}
		tmp = new ArrayList<Object>();
		tmp.add(1);
		tmp.add(2);
		tmp.add(3);
		V.add(tmp);
		
		// {1,2,2,3,4}
		tmp = new ArrayList<Object>();
		tmp.add(1);
		tmp.add(2);
		tmp.add(2);
		tmp.add(3);
		tmp.add(4);
		V.add(tmp);
		
		// {4,5,5,6}
		tmp = new ArrayList<Object>();
		tmp.add(4);
		tmp.add(5);
		tmp.add(5);
		tmp.add(6);
		V.add(tmp);
		
		// {4,6}
		tmp = new ArrayList<Object>();
		tmp.add(4);;
		tmp.add(6);
		V.add(tmp);
		
		// {0,9}
		tmp = new ArrayList<Object>();
		tmp.add(0);
		tmp.add(9);
		V.add(tmp);
		
		// {8,9,10}
		tmp = new ArrayList<Object>();
		tmp.add(8);
		tmp.add(9);
		tmp.add(10);
		V.add(tmp);
	}
	
	@Before
	public void setup() 
	{
		list = new MyListImpl();	
		suiteChainee = new ListeChaineeImpl();
		result = new ArrayList<Object>();
	}
	
	private String printList(MyList list)
	{
		String chaineContent = new String();
		for(int i = 0; i < list.getSize(); i++)
			chaineContent += " " + list.getAt(i);
		return chaineContent;
	}
	
	@Test
	public void O1_V1_W2_R4() throws IOException
	{
		String oper = OP.get(0);
		ArrayList<Object> val1 = V.get(0);
		ArrayList<Object> val2 = V.get(1);
		
		list = suiteChainee.build(oper, val1, val2);
		System.out.println("O1_V1_W2_R4:" + printList(list));
		
		result.add(1);

		assertTrue(list.getAt(2).equals(result));
	}

	@Test
	public void O2_V2_W2_R1() throws IOException
	{
		String oper = OP.get(1);
		ArrayList<Object> val1 = V.get(1);
		ArrayList<Object> val2 = V.get(2);
		
		list = suiteChainee.build(oper, val1, val2);
		System.out.println("O2_V2_W2_R1:" + printList(list));

		assertTrue(list.getAt(2).equals(result));
	}
	
	@Test
	public void O3_V3_W4_R2() throws IOException
	{
		String oper = OP.get(2);
		ArrayList<Object> val1 = V.get(3);
		ArrayList<Object> val2 = V.get(4);
		
		list = suiteChainee.build(oper, val1, val2);
		System.out.println("O3_V3_W4_R2:" + printList(list));

		assertTrue(list.getAt(2).equals(result));
	}
	
	@Test
	public void O4_V4_W3_R3() throws IOException
	{
		String oper = OP.get(3);
		ArrayList<Object> val1 = V.get(5);
		ArrayList<Object> val2 = V.get(6);
		
		list = suiteChainee.build(oper, val1, val2);
		System.out.println("O4_V4_W3_R3:" + printList(list));
		
		result.add(5);
		result.add(5);

		assertTrue(list.getAt(2).equals(result));
	}
	
	@Test
	public void O4_V3_W1_R3() throws IOException
	{
		String oper = OP.get(4);
		ArrayList<Object> val1 = V.get(7);
		ArrayList<Object> val2 = V.get(0);
		
		list = suiteChainee.build(oper, val1, val2);
		System.out.println("O4_V3_W1_R3:" + printList(list));

		result.add("false");

		assertTrue(list.getAt(2).equals(result));
	}
	
	@Test
	public void O6_V2_W4_R1() throws IOException
	{
		String oper = OP.get(5);
		ArrayList<Object> val1 = V.get(2);
		ArrayList<Object> val2 = V.get(8);
		
		list = suiteChainee.build(oper, val1, val2);
		System.out.println("O6_V2_W4_R1:" + printList(list));
		
		result.add("false");

		assertTrue(list.getAt(2).equals(result));
	}
	
	/**
	 * Modifications LAB3
	 */
	@Test
	public void Erreur() throws IOException
	{
		String oper = "Invalide";
		ArrayList<Object> val1 = V.get(2);
		ArrayList<Object> val2 = V.get(8);
		
		list = suiteChainee.build(oper, val1, val2);
		assertTrue(list.getSize() == 2);
	}
}
