mirror of https://github.com/apache/poi.git
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:
parent
488dff773a
commit
007a4d156a
|
@ -751,25 +751,28 @@ public class TestMathX extends AbstractNumericTestCase {
|
||||||
assertEquals("roundDown ", 100, MathX.roundDown(d, p));
|
assertEquals("roundDown ", 100, MathX.roundDown(d, p));
|
||||||
|
|
||||||
d = 0.049999999999999975d; p = 2;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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() {
|
public void testRoundUp() {
|
||||||
|
@ -819,25 +822,30 @@ public class TestMathX extends AbstractNumericTestCase {
|
||||||
assertEquals("roundUp ", 200, MathX.roundUp(d, p));
|
assertEquals("roundUp ", 200, MathX.roundUp(d, p));
|
||||||
|
|
||||||
d = 0.049999999999999975d; p = 2;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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() {
|
public void testCeiling() {
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
|
|
||||||
package org.apache.poi.ss.formula.functions;
|
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.ErrorEval;
|
||||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||||
|
@ -29,22 +32,58 @@ import org.apache.poi.ss.formula.eval.StringEval;
|
||||||
*
|
*
|
||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
*/
|
*/
|
||||||
public final class TestRoundFuncs extends TestCase {
|
public final class TestRoundFuncs {
|
||||||
private static final NumericFunction F = null;
|
// github-43
|
||||||
public void testRounddownWithStringArg() {
|
// 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 strArg = new StringEval("abc");
|
||||||
ValueEval[] args = { strArg, new NumberEval(2), };
|
ValueEval[] args = { strArg, new NumberEval(2), };
|
||||||
ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short)-1);
|
ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short)-1);
|
||||||
assertEquals(ErrorEval.VALUE_INVALID, result);
|
assertEquals(ErrorEval.VALUE_INVALID, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRoundupWithStringArg() {
|
@Test
|
||||||
|
public void testRoundUpWithStringArg() {
|
||||||
ValueEval strArg = new StringEval("abc");
|
ValueEval strArg = new StringEval("abc");
|
||||||
ValueEval[] args = { strArg, new NumberEval(2), };
|
ValueEval[] args = { strArg, new NumberEval(2), };
|
||||||
ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short)-1);
|
ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short)-1);
|
||||||
assertEquals(ErrorEval.VALUE_INVALID, result);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue