diff --git a/test/bytecode/operators/EqualOperatorTest.java b/test/bytecode/operators/EqualOperatorTest.java index b605799f..46720335 100644 --- a/test/bytecode/operators/EqualOperatorTest.java +++ b/test/bytecode/operators/EqualOperatorTest.java @@ -2,31 +2,29 @@ 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 EqualOperatorTest extends SourceFileBytecodeTest{ +public class EqualOperatorTest extends RelOperatorTest{ @Override protected void init() { testName = "EqualOperator"; rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; } - @Test - public void testConstruct() throws Exception{ - ClassLoader classLoader = getClassLoader(); + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } - Class cls = classLoader.loadClass(testName); - - Object obj = cls.newInstance(); - assertTrue(true); + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); } } diff --git a/test/bytecode/operators/GreaterEqualOperator.jav b/test/bytecode/operators/GreaterEqualOperator.jav new file mode 100644 index 00000000..798891f9 --- /dev/null +++ b/test/bytecode/operators/GreaterEqualOperator.jav @@ -0,0 +1,5 @@ +class GreaterEqualOperator{ + Boolean method(Integer x, Integer y){ + return x >= y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/GreaterEqualOperatorTest.java b/test/bytecode/operators/GreaterEqualOperatorTest.java new file mode 100644 index 00000000..41834e73 --- /dev/null +++ b/test/bytecode/operators/GreaterEqualOperatorTest.java @@ -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); + } +} diff --git a/test/bytecode/operators/GreaterOperator.jav b/test/bytecode/operators/GreaterOperator.jav new file mode 100644 index 00000000..f2c28682 --- /dev/null +++ b/test/bytecode/operators/GreaterOperator.jav @@ -0,0 +1,5 @@ +class GreaterOperator{ + Boolean method(Integer x, Integer y){ + return x > y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/GreaterOperatorTest.java b/test/bytecode/operators/GreaterOperatorTest.java new file mode 100644 index 00000000..7a562461 --- /dev/null +++ b/test/bytecode/operators/GreaterOperatorTest.java @@ -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); + } +} diff --git a/test/bytecode/operators/ModuloOperator.jav b/test/bytecode/operators/ModuloOperator.jav new file mode 100644 index 00000000..6a17f28e --- /dev/null +++ b/test/bytecode/operators/ModuloOperator.jav @@ -0,0 +1,5 @@ +class ModuloOperator{ + Integer method(Integer x, Integer y){ + return x % y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/ModuloOperatorTest.java b/test/bytecode/operators/ModuloOperatorTest.java new file mode 100644 index 00000000..5c0c600f --- /dev/null +++ b/test/bytecode/operators/ModuloOperatorTest.java @@ -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); + } +} diff --git a/test/bytecode/operators/NotEqualOperator.jav b/test/bytecode/operators/NotEqualOperator.jav new file mode 100644 index 00000000..68c8a168 --- /dev/null +++ b/test/bytecode/operators/NotEqualOperator.jav @@ -0,0 +1,5 @@ +class NotEqualOperator{ + Boolean method(Integer x, Integer y){ + return x != y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/NotEqualOperatorTest.java b/test/bytecode/operators/NotEqualOperatorTest.java new file mode 100644 index 00000000..89b2d871 --- /dev/null +++ b/test/bytecode/operators/NotEqualOperatorTest.java @@ -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); + } +} diff --git a/test/bytecode/operators/OROperatorTest.java b/test/bytecode/operators/OrOperatorTest.java similarity index 91% rename from test/bytecode/operators/OROperatorTest.java rename to test/bytecode/operators/OrOperatorTest.java index 7c648e88..8d8faaa9 100644 --- a/test/bytecode/operators/OROperatorTest.java +++ b/test/bytecode/operators/OrOperatorTest.java @@ -13,7 +13,7 @@ import org.junit.Test; import bytecode.SourceFileBytecodeTest; -public class OROperatorTest extends SourceFileBytecodeTest{ +public class OrOperatorTest extends SourceFileBytecodeTest{ @Override protected void init() { testName = "OrOperator"; diff --git a/test/bytecode/operators/RelOperatorTest.java b/test/bytecode/operators/RelOperatorTest.java new file mode 100644 index 00000000..59f3ded7 --- /dev/null +++ b/test/bytecode/operators/RelOperatorTest.java @@ -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(); +} diff --git a/test/bytecode/operators/SmallerEqualOperator.jav b/test/bytecode/operators/SmallerEqualOperator.jav new file mode 100644 index 00000000..b0448dba --- /dev/null +++ b/test/bytecode/operators/SmallerEqualOperator.jav @@ -0,0 +1,5 @@ +class SmallerEqualOperator{ + Boolean method(Integer x, Integer y){ + return x <= y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SmallerEqualOperatorTest.java b/test/bytecode/operators/SmallerEqualOperatorTest.java new file mode 100644 index 00000000..d4da5f6f --- /dev/null +++ b/test/bytecode/operators/SmallerEqualOperatorTest.java @@ -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); + } +} diff --git a/test/bytecode/operators/SmallerOperator.jav b/test/bytecode/operators/SmallerOperator.jav new file mode 100644 index 00000000..5ddc8c91 --- /dev/null +++ b/test/bytecode/operators/SmallerOperator.jav @@ -0,0 +1,5 @@ +class SmallerOperator{ + Boolean method(Integer x, Integer y){ + return x < y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SmallerOperatorTest.java b/test/bytecode/operators/SmallerOperatorTest.java new file mode 100644 index 00000000..2609b70f --- /dev/null +++ b/test/bytecode/operators/SmallerOperatorTest.java @@ -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); + } +}