package ch.ntb.inf.deep.ssa;

import java.io.IOException;

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

import ch.ntb.inf.deep.classItems.Class;
import ch.ntb.inf.deep.classItems.IClassFileConsts;
import ch.ntb.inf.deep.classItems.Type;

public class SSA03 extends TestSSA {

	@BeforeClass
	public static void setUp() {
		String workspace =System.getProperty("user.dir");
		String[] rootClassNames = new String[] { "ch/ntb/inf/deep/testClasses/T03Switch" };
		try {
			Class.buildSystem(rootClassNames,workspace, (1 << IClassFileConsts.atxCode)
					| (1 << IClassFileConsts.atxLocalVariableTable)
					| (1 << IClassFileConsts.atxLineNumberTable)
					| (1 << IClassFileConsts.atxExceptions));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (Type.nofRootClasses > 0) {
			createSSA(Type.rootClasses[0]);
		}
	}

	@Test
	public void testConstructor() {
		SSANode[] nodes = getAndTestSSA(0, 1, 0);
		testNode(nodes[0], 3, 0, 2);
	}
	
	@Test
	public void testSwitchNear1(){
		SSANode[] nodes = getAndTestSSA(1, 5, 0);
		testNode(nodes[0], 2, 0, 2);
		testNode(nodes[1], 2, 0, 2);
		testNode(nodes[2], 2, 0, 2);
		testNode(nodes[3], 2, 0, 2);
		testNode(nodes[4], 2, 0, 2);
	}
	
	@Test
	public void testSwitchNear2(){
		SSANode[] nodes = getAndTestSSA(2, 9, 0);
		testNode(nodes[0], 2, 0, 3);
		testNode(nodes[1], 2, 0, 3);
		testNode(nodes[2], 2, 0, 3);
		testNode(nodes[3], 3, 0, 3);
		testNode(nodes[4], 2, 0, 3);
		testNode(nodes[5], 2, 0, 3);
		testNode(nodes[6], 3, 1, 3);
		testNode(nodes[7], 2, 0, 3);
		testNode(nodes[8], 3, 1, 3);
	}
	
	@Test
	public void testSwitchFar1(){
		SSANode[] nodes = getAndTestSSA(3, 5, 0);
		testNode(nodes[0], 2, 0, 2);
		testNode(nodes[1], 2, 0, 2);
		testNode(nodes[2], 2, 0, 2);
		testNode(nodes[3], 2, 0, 2);
		testNode(nodes[4], 2, 0, 2);		
	}
	
	@Test
	public void testSwitchFar2(){
		SSANode[] nodes = getAndTestSSA(4, 10, 0);
		testNode(nodes[0], 2, 0, 2);
		testNode(nodes[1], 2, 0, 2);
		testNode(nodes[2], 1, 0, 2);
		testNode(nodes[3], 2, 0, 2);
		testNode(nodes[4], 3, 0, 2);
		testNode(nodes[5], 2, 0, 2);
		testNode(nodes[6], 1, 1, 2);
		testNode(nodes[7], 3, 0, 2);
		testNode(nodes[8], 2, 0, 2);
		testNode(nodes[9], 1, 1, 2);
	}

}

@@ -1647,32 +1647,250 @@
  3, 1, 3);%0D%0A%09%7D%0D%0A
+%09@Test%0D%0A%09public void testSwitchNear3()%7B%0D%0A%09%09SSANode%5B%5D nodes = getAndTestSSA(3, 4, 0);%0D%0A%09%09testNode(nodes%5B0%5D, 4, 0, 6);%0D%0A%09%09testNode(nodes%5B1%5D, 2, 0, 6);%0D%0A%09%09testNode(nodes%5B2%5D, 1, 0, 6);%0D%0A%09%09testNode(nodes%5B3%5D, 4, 0, 6);%0D%0A%09%7D%0D%0A
 %09%0D%0A%09@Test%0D%0A%09publ
@@ -1950,17 +1950,17 @@
 TestSSA(
-3
+4
 , 5, 0);
@@ -2204,17 +2204,17 @@
 TestSSA(
-4
+5
 , 10, 0)

add test case switchNear3