Skip to content

Commit

Permalink
github-43: add disabled unit test showing a problem with ROUNDUP(3987…
Browse files Browse the repository at this point in the history
…*0.2, 2). Thanks to @FishMeat.

#43

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1795265 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
onealj committed May 16, 2017
1 parent fec503f commit be5106a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
36 changes: 22 additions & 14 deletions src/testcases/org/apache/poi/ss/formula/functions/TestMathX.java
Original file line number Diff line number Diff line change
Expand Up @@ -751,25 +751,28 @@ public void testRoundDown() {
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() {
Expand Down Expand Up @@ -819,25 +822,30 @@ public void testRoundUp() {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ Licensed to the Apache Software Foundation (ASF) under one or more

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;
Expand All @@ -29,22 +32,58 @@ Licensed to the Apache Software Foundation (ASF) under one or more
*
* @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);
}
}

0 comments on commit be5106a

Please sign in to comment.