package de.unidortmund.dependencies.test;

import junit.framework.TestCase;
import de.unidortmund.dependencies.*;

public class VariableTest extends TestCase {
	
	private Value content1;
	private Value content2;
	private Value[] contents1;	
	private Value content3;
	private Value content4;
	private Value content5;
	private Value content6;
	private Value[] contents2;
	private Variable object;
	private Variable array1;
	private Variable array2;
	private Variable variable3;
	private Variable[] variables;

	

	@Override
	protected void setUp() throws Exception {
		Memory.clear();
		content1 = new IntValue(1);
		content2 = new CharValue('a');
		contents1 = new Value[]{content1, content2};
		content3 = new IntValue(3);
		content4 = new CharValue('d');
		content5 = new IntValue(5);
		contents2 = new Value[]{content3, content4, content5};
		content6 = new CharValue('f');
		super.setUp();
	}
	
	



	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.Variable(String, Content)'
	 */
	public void testVariableStringContent() {
		Variable variable = new Variable("a", content1);
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.Variable(String, Content[])'
	 */
	public void testVariableStringContentArray() {
		Variable variable = new Variable("array", contents1);
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.Variable(String, Variable[])'
	 */
	public void testVariableStringVariableArray() {
		initializeVariables();
	}
	
	private void initializeVariables() {
		array1 = new Variable("array1", contents1);
		array2 = new Variable("array2", contents2);
		variable3 = new Variable("a", content6);
		variables = new Variable[]{array1, array2, variable3};
		object = new Variable("object", variables);		
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.toString()'
	 */
	public void testToString() {
		initializeVariables();
		assert variable3.toString().equals("a a(3,7) a(2,7) a(1,5) f") : variable3
				.toString();
		String string = "array2 a(3,3) a(2,3)\n"
				+ "a(3,4) a(2,4) a(1,2) 3\n" + "a(3,5) a(2,5) a(1,3) d\n"
				+ "a(3,6) a(2,6) a(1,4) 5";
		assert array2.toString().equals(string) : array2;
		string = "object a(3,8) a(2,8)\n" + "a(3,9) a(2,0)\n"
				+ "a(3,1) a(2,1) a(1,0) 1\n" + "a(3,2) a(2,2) a(1,1) a\n"
				+ "a(3,10) a(2,3)\n" + "a(3,4) a(2,4) a(1,2) 3\n"
				+ "a(3,5) a(2,5) a(1,3) d\n" + "a(3,6) a(2,6) a(1,4) 5\n"
				+ "a(3,11) a(2,7) a(1,5) f";
		assert object.toString().equals(string) : object;
	}


	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.isComposite()'
	 */
	public void testIsComposite() {
		initializeVariables();
		assert !variable3.isComposite();
		assert array2.isComposite();
		assert array1.isComposite();
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.getVariableAtIndex(int)'
	 */
	public void testGetVariableAtIndex() {
		initializeVariables();
		Variable v1 = array2.getVariableAtIndex(1);
		Variable v2 = object.getVariableAtIndex(2);
		assert v1.getValue() == content4;
		assert v2.getValue() == content6;
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Variable.getAllIndexVariables()'
	 */
	public void testGetAllIndexVariables() {
		initializeVariables();
		Variable[] vs2 = array2.getAllIndexVariables();
		Variable[] vs1 = object.getAllIndexVariables();
		assert vs2.length == 3;
		assert vs1.length == 3;
	}

	public void testGetContent() {
		initializeVariables();
		assert variable3.getValue() == content6;
	}

}
