modified: ../../test/bytecode/LambdaTest.java
noch unvllstaendig modified: ../../test/bytecode/MatrixTest.java Test korrekt modified: ../../test/bytecode/javFiles/Matrix.jav import byte entfernt, so dass Laufzeit passt
This commit is contained in:
parent
16b7db9218
commit
c3ca4777bb
@ -1,6 +1,12 @@
|
||||
package bytecode;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -10,6 +16,10 @@ public class LambdaTest {
|
||||
private static String path;
|
||||
private static File fileToTest;
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@Test
|
||||
public void generateBC() throws Exception {
|
||||
@ -17,6 +27,17 @@ public class LambdaTest {
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
|
||||
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Lambda");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
//Class<?>
|
||||
Object lambda = (m.invoke(instanceOfClass)); //.getClass();
|
||||
//Method apply = lambda.getMethod("apply", Integer.class);
|
||||
//Integer result = (Integer) apply.invoke(lambda, 77);
|
||||
//assertEquals(77, result);
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,17 +24,10 @@ public class MatrixTest {
|
||||
private static String pathToClassFile;
|
||||
private static Object instanceOfClass_m1;
|
||||
private static Object instanceOfClass_m2;
|
||||
private static Object instanceOfClass_m3;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
// path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
|
||||
// fileToTest = new File(path);
|
||||
// compiler = new JavaTXCompiler(fileToTest);
|
||||
// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
||||
// compiler.generateBytecode(pathToClassFile);
|
||||
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
// classToTest = loader.loadClass("Matrix");
|
||||
// instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
||||
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
@ -43,31 +36,6 @@ public class MatrixTest {
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Matrix");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
|
||||
// Vector<Vector<Integer>> m1 = new Vector<>();
|
||||
// Vector<Integer> r1 = new Vector<>();
|
||||
// r1.addElement(1);
|
||||
// r1.addElement(0);
|
||||
// m1.addElement(r1);
|
||||
// Vector<Integer> r2 = new Vector<>();
|
||||
// r2.addElement(0);
|
||||
// r2.addElement(1);
|
||||
// m1.add(r2);
|
||||
//
|
||||
// Vector<Vector<Integer>> m2 = new Vector<>();
|
||||
// Vector<Integer> mr1 = new Vector<>();
|
||||
// mr1.addElement(1);
|
||||
// mr1.addElement(2);
|
||||
// m2.add(mr1);
|
||||
// Vector<Integer> mr2 = new Vector<>();
|
||||
// mr2.addElement(3);
|
||||
// mr2.addElement(4);
|
||||
// m2.add(mr2);
|
||||
|
||||
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v1 = new Vector<Integer> ();
|
||||
v1.addElement(2);
|
||||
@ -80,7 +48,7 @@ public class MatrixTest {
|
||||
//m1.addElement(v2);
|
||||
vv.addElement(v1);
|
||||
vv.addElement(v2);
|
||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(vv); //Matrix m1 = new Matrix(vv);
|
||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
||||
|
||||
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v3 = new Vector<Integer> ();
|
||||
@ -94,14 +62,29 @@ public class MatrixTest {
|
||||
//m2.addElement(v4);
|
||||
vv1.addElement(v3);
|
||||
vv1.addElement(v4);
|
||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor().newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||
|
||||
|
||||
|
||||
//Matrix m3 = m1.mul(vv1);
|
||||
Method m = classToTest.getDeclaredMethod("mul", Double.class);
|
||||
Object result = m.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
||||
|
||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
||||
Vector<Integer> v5 = new Vector<Integer> ();
|
||||
v5.addElement(10);
|
||||
v5.addElement(10);
|
||||
Vector<Integer> v6 = new Vector<Integer> ();
|
||||
v6.addElement(15);
|
||||
v6.addElement(15);
|
||||
//Matrix m2 = new Matrix();
|
||||
//m2.addElement(v3);
|
||||
//m2.addElement(v4);
|
||||
res.addElement(v5);
|
||||
res.addElement(v6);
|
||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||
assertEquals(result, instanceOfClass_m3);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Byte;
|
||||
//import java.lang.Byte;
|
||||
import java.lang.Boolean;
|
||||
|
||||
public class Matrix extends Vector<Vector<Integer>> {
|
||||
@ -9,8 +9,8 @@ public class Matrix extends Vector<Vector<Integer>> {
|
||||
}
|
||||
|
||||
Matrix(vv) {
|
||||
//Integer i;
|
||||
var i = 0;
|
||||
Integer i;
|
||||
i = 0;
|
||||
while(i < vv.size()) {
|
||||
// Boolean a = this.add(vv.elementAt(i));
|
||||
this.add(vv.elementAt(i));
|
||||
|
Loading…
Reference in New Issue
Block a user