git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882708 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2020-10-20 16:08:29 +00:00
parent dd9f132c23
commit 02da9fd353
1 changed files with 41 additions and 41 deletions

View File

@ -30,56 +30,56 @@ import org.junit.Test;
* @author Stephen Wolke (smwolke at geistig.com) * @author Stephen Wolke (smwolke at geistig.com)
*/ */
public final class TestTrunc extends BaseTestNumeric { public final class TestTrunc extends BaseTestNumeric {
private static final NumericFunction F = null; private static final NumericFunction F = null;
@Test @Test
public void testTruncWithStringArg() { public void testTruncWithStringArg() {
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.TRUNC.evaluate(args, -1, (short)-1); ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
Assert.assertEquals(ErrorEval.VALUE_INVALID, result); Assert.assertEquals(ErrorEval.VALUE_INVALID, result);
} }
@Test @Test
public void testTruncWithWholeNumber() { public void testTruncWithWholeNumber() {
ValueEval[] args = { new NumberEval(200), new NumberEval(2) }; ValueEval[] args = { new NumberEval(200), new NumberEval(2) };
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1); ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
assertEquals("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval)result).getNumberValue()); assertEquals("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval)result).getNumberValue());
} }
@Test @Test
public void testTruncWithDecimalNumber() { public void testTruncWithDecimalNumber() {
ValueEval[] args = { new NumberEval(2.612777), new NumberEval(3) }; ValueEval[] args = { new NumberEval(2.612777), new NumberEval(3) };
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1); ValueEval result = F.TRUNC.evaluate(args, -1, (short)-1);
assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue()); assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue());
} }
@Test @Test
public void testTruncWithProblematicDecimalNumber() { public void testTruncWithProblematicDecimalNumber() {
ValueEval[] args = { new NumberEval(0.29), new NumberEval(2) }; ValueEval[] args = { new NumberEval(0.29), new NumberEval(2) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
assertEquals("TRUNC", (new NumberEval(0.29d)).getNumberValue(), ((NumberEval)result).getNumberValue()); assertEquals("TRUNC", (new NumberEval(0.29d)).getNumberValue(), ((NumberEval)result).getNumberValue());
} }
@Test @Test
public void testTruncWithProblematicCalculationResult() { public void testTruncWithProblematicCalculationResult() {
ValueEval[] args = { new NumberEval(21.624d / 24d + .009d), new NumberEval(2) }; ValueEval[] args = { new NumberEval(21.624d / 24d + .009d), new NumberEval(2) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
assertEquals("TRUNC", (new NumberEval(0.91d)).getNumberValue(), ((NumberEval)result).getNumberValue()); assertEquals("TRUNC", (new NumberEval(0.91d)).getNumberValue(), ((NumberEval)result).getNumberValue());
} }
@Test @Test
public void testTruncWithDecimalNumberOneArg() { public void testTruncWithDecimalNumberOneArg() {
ValueEval[] args = { new NumberEval(2.612777) }; ValueEval[] args = { new NumberEval(2.612777) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1); ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue()); assertEquals("TRUNC", (new NumberEval(2d)).getNumberValue(), ((NumberEval)result).getNumberValue());
} }
@Test @Test
public void testNegative() { public void testNegative() {
ValueEval[] args = { new NumberEval(-8.9), new NumberEval(0) }; ValueEval[] args = { new NumberEval(-8.9), new NumberEval(0) };
@SuppressWarnings("static-access") @SuppressWarnings("static-access")