package de.unidortmund.dependencies.test;

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

public class MemoryTest extends TestCase {


	private Variable object;
	Variable array1;
	Variable array2;
	Variable variable3;
	Variable[] variables;
	Variable variable4;
	
	@Override
	protected void setUp() throws Exception {
		Memory.clear();
		Value content1 = new IntValue(1);
		Value content2 = new CharValue('a');
		Value[] contents1 = new Value[]{content1, content2, new CharValue('c')};
		Value content3 = new IntValue(3);
		Value content4 = new CharValue('d');
		Value content5 = new IntValue(5);
		Value[] contents2 = new Value[]{content3, content4, content5};
		Value content6 = new CharValue('f');
		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);		
		
		super.setUp();
	}
	
	/*
	 * Test method for 'de.unidortmund.dependencies.Memory.registerSlot(Slot)'
	 */
	public void testRegisterSlot() {
		assert variable3.getSlot().getIndex() == 8 : variable3.getSlot().getIndex();
		assert variable3.getSlot().getLevel() == 3;
		assert ((Slot) variable3.getSlot().getContent()).getLevel() == 2;
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Memory.getSlot(int, int)'
	 */
	public void testGetSlot() {
		assert Memory.getSlot(2,8) == variable3.getSlot().getContent();
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Memory.m33(Variable, Variable)'
	 */
	public void testM33() {
		Content value = array2.getSlot().getContent();
		Memory.m33(array1, array2);
		assert array1.getSlot().getContent() == value;
		assert array2.getSlot().getContent() == value;
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Memory.m22(Variable, Variable)'
	 */
	public void testM22() {
		Slot slot31 = (Slot) array1.getSlot().getContent();
		Slot slot32 = (Slot) array2.getSlot().getContent();
		Content value = slot32.getContent();
		Memory.m22(array1, array2);
		assert array1.getSlot().getContent() == slot31;
		assert array2.getSlot().getContent() == slot32;
		assert slot31.getContent() == value;
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Memory.m23(Variable, Variable)'
	 */
	public void testM23() {
		Slot slot31 = (Slot) array1.getSlot().getContent();
		Slot slot32 = (Slot) array2.getSlot().getContent();
		Content value =  slot32.getContent();
		Memory.m23(array1, array2);
		assert array1.getSlot().getContent() == slot31;
		assert array2.getSlot().getContent() == slot32;
		assert ((Slot) slot31.getContent()).getContent() == value;
	}

	/*
	 * Test method for 'de.unidortmund.dependencies.Memory.m11(Variable, Variable)'
	 */
	public void testM11() {
		Memory.m11(array1, array2);
		Variable vs1[] = array1.getAllIndexVariables();
		Variable vs2[] = array2.getAllIndexVariables();
		for (int i = 0; i < vs1.length; i ++) {
			assert vs1[i].getValue() == vs2[i].getValue();
		}
	}

}
