You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2017/05/16 03:04:12 UTC

svn commit: r1795265 - in /poi/trunk/src/testcases/org/apache/poi/ss/formula/functions: TestMathX.java TestRoundFuncs.java

Author: onealj
Date: Tue May 16 03:04:12 2017
New Revision: 1795265

URL: http://svn.apache.org/viewvc?rev=1795265&view=rev
Log:
github-43: add disabled unit test showing a problem with ROUNDUP(3987*0.2, 2). Thanks to @FishMeat.
https://github.com/apache/poi/pull/43

Modified:
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java?rev=1795265&r1=1795264&r2=1795265&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java Tue May 16 03:04:12 2017
@@ -751,25 +751,28 @@ public class TestMathX extends AbstractN
         assertEquals("roundDown ", 100, MathX.roundDown(d, p));
         
         d = 0.049999999999999975d; p = 2;
-        assertEquals("round ", 0.04d, MathX.roundDown(d, p));
+        assertEquals("roundDown ", 0.04d, MathX.roundDown(d, p));
 
         d = 0.049999999999999975d; p = 1;
-        assertEquals("round ", 0.0d, MathX.roundDown(d, p));
+        assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p));
         
         d = Double.NaN; p = 1;
-        assertEquals("round ", Double.NaN, MathX.roundDown(d, p));
+        assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
 
         d = Double.POSITIVE_INFINITY; p = 1;
-        assertEquals("round ", Double.NaN, MathX.roundDown(d, p));
+        assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
 
         d = Double.NEGATIVE_INFINITY; p = 1;
-        assertEquals("round ", Double.NaN, MathX.roundDown(d, p));
+        assertEquals("roundDown ", Double.NaN, MathX.roundDown(d, p));
 
         d = Double.MAX_VALUE; p = 1;
-        assertEquals("round ", Double.MAX_VALUE, MathX.roundDown(d, p));
+        assertEquals("roundDown ", Double.MAX_VALUE, MathX.roundDown(d, p));
 
         d = Double.MIN_VALUE; p = 1;
-        assertEquals("round ", 0.0d, MathX.roundDown(d, p));
+        assertEquals("roundDown ", 0.0d, MathX.roundDown(d, p));
+
+        d = 3987 * 0.2; p = 2;
+        assertEquals("roundDown ", 797.40, MathX.round(d, p));
     }
 
     public void testRoundUp() {
@@ -819,25 +822,30 @@ public class TestMathX extends AbstractN
         assertEquals("roundUp ", 200, MathX.roundUp(d, p));
         
         d = 0.049999999999999975d; p = 2;
-        assertEquals("round ", 0.05d, MathX.roundUp(d, p));
+        assertEquals("roundUp ", 0.05d, MathX.roundUp(d, p));
 
         d = 0.049999999999999975d; p = 1;
-        assertEquals("round ", 0.1d, MathX.roundUp(d, p));
+        assertEquals("roundUp ", 0.1d, MathX.roundUp(d, p));
         
         d = Double.NaN; p = 1;
-        assertEquals("round ", Double.NaN, MathX.roundUp(d, p));
+        assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p));
 
         d = Double.POSITIVE_INFINITY; p = 1;
-        assertEquals("round ", Double.NaN, MathX.roundUp(d, p));
+        assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p));
 
         d = Double.NEGATIVE_INFINITY; p = 1;
-        assertEquals("round ", Double.NaN, MathX.roundUp(d, p));
+        assertEquals("roundUp ", Double.NaN, MathX.roundUp(d, p));
 
         d = Double.MAX_VALUE; p = 1;
-        assertEquals("round ", Double.MAX_VALUE, MathX.roundUp(d, p));
+        assertEquals("roundUp ", Double.MAX_VALUE, MathX.roundUp(d, p));
 
         d = Double.MIN_VALUE; p = 1;
-        assertEquals("round ", 0.1d, MathX.roundUp(d, p));
+        assertEquals("roundUp ", 0.1d, MathX.roundUp(d, p));
+
+        //github-43: https://github.com/apache/poi/pull/43
+        //@Ignore("ROUNDUP(3987*0.2, 2) currently fails by returning 797.41")
+        //d = 3987 * 0.2; p = 2;
+        //assertEquals("roundUp ", 797.40, MathX.roundUp(d, p));
     }
 
     public void testCeiling() {

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java?rev=1795265&r1=1795264&r2=1795265&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestRoundFuncs.java Tue May 16 03:04:12 2017
@@ -17,7 +17,10 @@
 
 package org.apache.poi.ss.formula.functions;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.junit.Ignore;
 
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
@@ -29,22 +32,58 @@ import org.apache.poi.ss.formula.eval.St
  *
  * @author Josh Micich
  */
-public final class TestRoundFuncs extends TestCase {
-	private static final NumericFunction F = null;
-	public void testRounddownWithStringArg() {
+public final class TestRoundFuncs {
+	// github-43
+	// https://github.com/apache/poi/pull/43
+    @Ignore("ROUNDUP(3987*0.2, 2) currently fails by returning 797.41")
+	@Test
+	public void testRoundUp() {
+		assertRoundUpEquals(797.40, 3987*0.2, 2, 1e-10);
+	}
 
+	@Test
+	public void testRoundDown() {
+		assertRoundDownEquals(797.40, 3987*0.2, 2, 1e-10);
+	}
+
+	@Test
+	public void testRound() {
+		assertRoundEquals(797.40, 3987*0.2, 2, 1e-10);
+	}
+
+	@Test
+	public void testRoundDownWithStringArg() {
 		ValueEval strArg = new StringEval("abc");
 		ValueEval[] args = { strArg, new NumberEval(2), };
 		ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short)-1);
 		assertEquals(ErrorEval.VALUE_INVALID, result);
 	}
 
-	public void testRoundupWithStringArg() {
-
+	@Test
+	public void testRoundUpWithStringArg() {
 		ValueEval strArg = new StringEval("abc");
 		ValueEval[] args = { strArg, new NumberEval(2), };
 		ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short)-1);
 		assertEquals(ErrorEval.VALUE_INVALID, result);
 	}
 
+
+
+    private static void assertRoundFuncEquals(Function func, double expected, double number, double places, double tolerance) {
+		ValueEval[] args = { new NumberEval( number ), new NumberEval(places), };
+		NumberEval result = (NumberEval) func.evaluate(args, -1, (short)-1);
+		assertEquals(expected, result.getNumberValue(), tolerance);
+    }
+
+    private static void assertRoundEquals(double expected, double number, double places, double tolerance) {
+		TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUND, expected, number, places, tolerance);
+    }
+
+    private static void assertRoundUpEquals(double expected, double number, double places, double tolerance) {
+		TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUNDUP, expected, number, places, tolerance);
+    }
+
+    private static void assertRoundDownEquals(double expected, double number, double places, double tolerance) {
+		TestRoundFuncs.assertRoundFuncEquals(NumericFunction.ROUNDDOWN, expected, number, places, tolerance);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org