Signed-off-by: Arthur HUILLET <[email protected]>
---
Makefile | 1 +
regression/jvm/FloatArithmeticTest.java | 126 +++++++++++++++++++++++++++++++
regression/jvm/TestCase.java | 5 +
3 files changed, 132 insertions(+), 0 deletions(-)
create mode 100644 regression/jvm/FloatArithmeticTest.java
diff --git a/Makefile b/Makefile
index 943f0e4..a355b16 100644
--- a/Makefile
+++ b/Makefile
@@ -214,6 +214,7 @@ REGRESSION_TEST_SUITE_CLASSES = \
regression/jvm/ExitStatusIsZeroTest.class \
regression/jvm/LoadConstantsTest.class \
regression/jvm/IntegerArithmeticTest.class \
+ regression/jvm/FloatArithmeticTest.class \
regression/jvm/LongArithmeticTest.class \
regression/jvm/ObjectCreationAndManipulationTest.class \
regression/jvm/ControlTransferTest.class \
diff --git a/regression/jvm/FloatArithmeticTest.java
b/regression/jvm/FloatArithmeticTest.java
new file mode 100644
index 0000000..efa3b9e
--- /dev/null
+++ b/regression/jvm/FloatArithmeticTest.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2006, 2009 Pekka Enberg
+ *
+ * This file is released under the GPL version 2 with the following
+ * clarification and special exception:
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library. Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under terms
+ * of your choice, provided that you also meet, for each linked independent
+ * module, the terms and conditions of the license of that module. An
+ * independent module is a module which is not derived from or based on
+ * this library. If you modify this library, you may extend this exception
+ * to your version of the library, but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version.
+ *
+ * Please refer to the file LICENSE for details.
+ */
+package jvm;
+
+/**
+ * @author Pekka Enberg
+ */
+public class FloatArithmeticTest extends TestCase {
+ public static void testFloatAddition() {
+ assertEquals(-1.5f, add(0.5f, -2.0f));
+ assertEquals( 0.0f, add(1.0f, -1.0f));
+ assertEquals( 0.0f, add(0.0f, 0.0f));
+ assertEquals( 1.5f, add(0.3f, 1.2f));
+ assertEquals( 3.1415f, add(1.14f, 2.0015f));
+ }
+
+ public static float add(float augend, float addend) {
+ return augend + addend;
+ }
+
+ public static void testFloatAdditionLocalSlot() {
+ float x = 1.234567f;
+ float y = 7.654321f;
+ float result = (1.111111f + x) + (0.0f + y);
+
+ assertEquals(9.999999f, result);
+ }
+
+ public static void testFloatSubtraction() {
+ assertEquals(-1.5f, sub(-2.5f, -1.0f));
+ assertEquals( 0.0f, sub(-1.0f, -1.0f));
+ assertEquals( 0.0f, sub( 0.0f, 0.0f));
+ assertEquals(-1.5f, sub( -0.5f, 1.0f));
+ assertEquals(-2.5f, sub( 1, 3.5f));
+ }
+
+ public static float sub(float minuend, float subtrahend) {
+ return minuend - subtrahend;
+ }
+
+ public static void testFloatSubtractionImmediateLocal() {
+ float x = 11.000000f;
+ float y = 9.999999f;
+ float result = (1.0f - x) - (0.0f - y);
+
+ assertEquals(-0.000001f, result);
+ }
+
+ public static void testFloatMultiplication() {
+ assertEquals( 1.0f, mul(-1.0f, -1.0f));
+ assertEquals(-3f, mul(-1.5f, 2f));
+ assertEquals(-1.0f, mul( 1.0f, -1.0f));
+ assertEquals( 12f, mul( -3f, -4f));
+ assertEquals( 0.0f, mul( 0.0f, 1.0f));
+ assertEquals( 0.0f, mul( 1.0f, 0.0f));
+ assertEquals( 6.4f, mul( 2.0f, 3.2f));
+ }
+
+ public static float mul(float multiplicand, float multiplier) {
+ return multiplicand * multiplier;
+ }
+
+ public static void testFloatDivision() {
+ assertEquals(-1.0f, div( 1.0f, -1.0f));
+ assertEquals(-1.0f, div(-1.0f, 1.0f));
+ assertEquals( 1.0f, div(-1.0f, -1.0f));
+ assertEquals( 1.0f, div( 1.0f, 1.0f));
+ assertEquals( 1.5f, div( 3.0f, 2.0f));
+ assertEquals( 2.0f, div( 2.0f, 1.0f));
+ assertEquals( 0.5f, div( 1.0f, 2.0f));
+ }
+
+ public static float div(float dividend, float divisor) {
+ return dividend / divisor;
+ }
+
+ public static float rem(float dividend, float divisor) {
+ return dividend % divisor;
+ }
+
+ public static void testFloatNegation() {
+ assertEquals(-1.5f, neg( 1.5f));
+ assertEquals( 0.0f, neg( 0.0f));
+ assertEquals( 1.3f, neg(-1.3f));
+ }
+
+ public static float neg(float n) {
+ return -n;
+ }
+
+ public static void main(String[] args) {
+/*
+ testFloatAddition();
+ testFloatAdditionLocalSlot();
+ testFloatSubtraction();
+ testFloatSubtractionImmediateLocal();
+ testFloatMultiplication();
+ testFloatDivision();
+ testFloatNegation();
+*/
+ exit();
+ }
+}
diff --git a/regression/jvm/TestCase.java b/regression/jvm/TestCase.java
index 54f0c45..d6e92ba 100644
--- a/regression/jvm/TestCase.java
+++ b/regression/jvm/TestCase.java
@@ -42,6 +42,11 @@ public class TestCase {
}
}
+ public static void assertEquals(float expected, float actual) {
+ if (expected != actual) {
+ fail(/* "Expected '" + expected + "', but was '" + actual + "'."
*/);
+ }
+ }
protected static void assertEquals(Object expected, Object actual) {
if (expected != actual) {
fail(/* "Expected '" + expected + "', but was '" + actual + "'."
*/);
--
1.6.3.2
------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel