- Tests für Vergleichsoperatoren angelegt

This commit is contained in:
Enrico Schrödter 2016-04-27 15:41:49 +02:00
parent b3e13d09b9
commit bbb79b1a1d
15 changed files with 333 additions and 16 deletions

View File

@ -2,31 +2,29 @@ package bytecode.operators;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import bytecode.SourceFileBytecodeTest; import bytecode.SourceFileBytecodeTest;
public class EqualOperatorTest extends SourceFileBytecodeTest{ public class EqualOperatorTest extends RelOperatorTest{
@Override @Override
protected void init() { protected void init() {
testName = "EqualOperator"; testName = "EqualOperator";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
} }
@Test @Override
public void testConstruct() throws Exception{ protected Boolean getTest1x2ReturnValue() {
ClassLoader classLoader = getClassLoader(); return new Boolean(false);
}
@Override
protected Boolean getTest2x2ReturnValue() {
return new Boolean(true);
}
Class cls = classLoader.loadClass(testName); @Override
protected Boolean getTest2x1ReturnValue() {
Object obj = cls.newInstance(); return new Boolean(false);
assertTrue(true);
} }
} }

View File

@ -0,0 +1,5 @@
class GreaterEqualOperator{
Boolean method(Integer x, Integer y){
return x >= y;
}
}

View File

@ -0,0 +1,30 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class GreaterEqualOperatorTest extends RelOperatorTest{
@Override
protected void init() {
testName = "GreaterEqualOperator";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Override
protected Boolean getTest1x2ReturnValue() {
return new Boolean(false);
}
@Override
protected Boolean getTest2x2ReturnValue() {
return new Boolean(true);
}
@Override
protected Boolean getTest2x1ReturnValue() {
return new Boolean(true);
}
}

View File

@ -0,0 +1,5 @@
class GreaterOperator{
Boolean method(Integer x, Integer y){
return x > y;
}
}

View File

@ -0,0 +1,30 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class GreaterOperatorTest extends RelOperatorTest{
@Override
protected void init() {
testName = "GreaterOperator";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Override
protected Boolean getTest1x2ReturnValue() {
return new Boolean(false);
}
@Override
protected Boolean getTest2x2ReturnValue() {
return new Boolean(false);
}
@Override
protected Boolean getTest2x1ReturnValue() {
return new Boolean(true);
}
}

View File

@ -0,0 +1,5 @@
class ModuloOperator{
Integer method(Integer x, Integer y){
return x % y;
}
}

View File

@ -0,0 +1,53 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;
import org.junit.Ignore;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class ModuloOperatorTest extends SourceFileBytecodeTest{
@Override
protected void init() {
testName = "ModuloOperator";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
@Test
public void testTwoIntegers() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Integer x = new Integer(1);
Integer y = new Integer(2);
Class[] params = new Class[]{
x.getClass(),
y.getClass(),
};
Method method = cls.getDeclaredMethod("method", params);
Integer returnValue = (Integer) method.invoke(obj, x, y);
assertEquals(new Integer(1), returnValue);
}
}

View File

@ -0,0 +1,5 @@
class NotEqualOperator{
Boolean method(Integer x, Integer y){
return x != y;
}
}

View File

@ -0,0 +1,30 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class NotEqualOperatorTest extends RelOperatorTest{
@Override
protected void init() {
testName = "NotEqualOperator";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Override
protected Boolean getTest1x2ReturnValue() {
return new Boolean(true);
}
@Override
protected Boolean getTest2x2ReturnValue() {
return new Boolean(false);
}
@Override
protected Boolean getTest2x1ReturnValue() {
return new Boolean(true);
}
}

View File

@ -13,7 +13,7 @@ import org.junit.Test;
import bytecode.SourceFileBytecodeTest; import bytecode.SourceFileBytecodeTest;
public class OROperatorTest extends SourceFileBytecodeTest{ public class OrOperatorTest extends SourceFileBytecodeTest{
@Override @Override
protected void init() { protected void init() {
testName = "OrOperator"; testName = "OrOperator";

View File

@ -0,0 +1,86 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public abstract class RelOperatorTest extends SourceFileBytecodeTest{
@Test
public void testConstruct() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
assertTrue(true);
}
@Test
public void test1x2() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Integer x = new Integer(1);
Integer y = new Integer(2);
Class[] params = new Class[]{
x.getClass(),
y.getClass(),
};
Method method = cls.getDeclaredMethod("method", params);
Boolean returnValue = (Boolean) method.invoke(obj, x, y);
assertEquals(getTest1x2ReturnValue(), returnValue);
}
@Test
public void test2x2() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Integer x = new Integer(2);
Integer y = new Integer(2);
Class[] params = new Class[]{
x.getClass(),
y.getClass(),
};
Method method = cls.getDeclaredMethod("method", params);
Boolean returnValue = (Boolean) method.invoke(obj, x, y);
assertEquals(getTest2x2ReturnValue(), returnValue);
}
@Test
public void test2x1() throws Exception{
ClassLoader classLoader = getClassLoader();
Class cls = classLoader.loadClass(testName);
Object obj = cls.newInstance();
Integer x = new Integer(2);
Integer y = new Integer(2);
Class[] params = new Class[]{
x.getClass(),
y.getClass(),
};
Method method = cls.getDeclaredMethod("method", params);
Boolean returnValue = (Boolean) method.invoke(obj, x, y);
assertEquals(getTest2x1ReturnValue(), returnValue);
}
protected abstract Boolean getTest1x2ReturnValue();
protected abstract Boolean getTest2x2ReturnValue();
protected abstract Boolean getTest2x1ReturnValue();
}

View File

@ -0,0 +1,5 @@
class SmallerEqualOperator{
Boolean method(Integer x, Integer y){
return x <= y;
}
}

View File

@ -0,0 +1,30 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class SmallerEqualOperatorTest extends RelOperatorTest{
@Override
protected void init() {
testName = "SmallerEqual";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Override
protected Boolean getTest1x2ReturnValue() {
return new Boolean(true);
}
@Override
protected Boolean getTest2x2ReturnValue() {
return new Boolean(true);
}
@Override
protected Boolean getTest2x1ReturnValue() {
return new Boolean(false);
}
}

View File

@ -0,0 +1,5 @@
class SmallerOperator{
Boolean method(Integer x, Integer y){
return x < y;
}
}

View File

@ -0,0 +1,30 @@
package bytecode.operators;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Test;
import bytecode.SourceFileBytecodeTest;
public class SmallerOperatorTest extends RelOperatorTest{
@Override
protected void init() {
testName = "Smaller";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/";
}
@Override
protected Boolean getTest1x2ReturnValue() {
return new Boolean(true);
}
@Override
protected Boolean getTest2x2ReturnValue() {
return new Boolean(false);
}
@Override
protected Boolean getTest2x1ReturnValue() {
return new Boolean(false);
}
}