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

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1795265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-05-16 03:04:12 +00:00
parent fec503f1de
commit be5106a1d7
2 changed files with 67 additions and 20 deletions

View File

@ -751,25 +751,28 @@ public class TestMathX extends AbstractNumericTestCase {
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 AbstractNumericTestCase {
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() {

View File

@ -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.StringEval;
*
* @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);
}
}