aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java87
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java88
2 files changed, 131 insertions, 44 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java
new file mode 100644
index 0000000..ba6fcf0
--- /dev/null
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java
@@ -0,0 +1,87 @@
+/*
+Copyright (c) 2018 James Ahlborn
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package com.healthmarketscience.jackcess.impl;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ *
+ * @author James Ahlborn
+ */
+public class NumberFormatterTest extends TestCase
+{
+
+ public NumberFormatterTest(String name) {
+ super(name);
+ }
+
+ public void testDoubleFormat() throws Exception
+ {
+ assertEquals("894984737284944", NumberFormatter.format(894984737284944d));
+ assertEquals("-894984737284944", NumberFormatter.format(-894984737284944d));
+ assertEquals("8949.84737284944", NumberFormatter.format(8949.84737284944d));
+ assertEquals("8949847372844", NumberFormatter.format(8949847372844d));
+ assertEquals("8949.847384944", NumberFormatter.format(8949.847384944d));
+ assertEquals("8.94985647372849E+16", NumberFormatter.format(89498564737284944d));
+ assertEquals("-8.94985647372849E+16", NumberFormatter.format(-89498564737284944d));
+ assertEquals("895649.847372849", NumberFormatter.format(895649.84737284944d));
+ assertEquals("300", NumberFormatter.format(300d));
+ assertEquals("-300", NumberFormatter.format(-300d));
+ assertEquals("0.3", NumberFormatter.format(0.3d));
+ assertEquals("0.1", NumberFormatter.format(0.1d));
+ assertEquals("2.3423421E-12", NumberFormatter.format(0.0000000000023423421d));
+ assertEquals("2.3423421E-11", NumberFormatter.format(0.000000000023423421d));
+ assertEquals("2.3423421E-10", NumberFormatter.format(0.00000000023423421d));
+ assertEquals("-2.3423421E-10", NumberFormatter.format(-0.00000000023423421d));
+ assertEquals("2.34234214E-12", NumberFormatter.format(0.00000000000234234214d));
+ assertEquals("2.342342156E-12", NumberFormatter.format(0.000000000002342342156d));
+ assertEquals("0.000000023423421", NumberFormatter.format(0.000000023423421d));
+ assertEquals("2.342342133E-07", NumberFormatter.format(0.0000002342342133d));
+ assertEquals("1.#INF", NumberFormatter.format(Double.POSITIVE_INFINITY));
+ assertEquals("-1.#INF", NumberFormatter.format(Double.NEGATIVE_INFINITY));
+ assertEquals("1.#QNAN", NumberFormatter.format(Double.NaN));
+ }
+
+ public void testFloatFormat() throws Exception
+ {
+ assertEquals("8949847", NumberFormatter.format(8949847f));
+ assertEquals("-8949847", NumberFormatter.format(-8949847f));
+ assertEquals("8949.847", NumberFormatter.format(8949.847f));
+ assertEquals("894984", NumberFormatter.format(894984f));
+ assertEquals("8949.84", NumberFormatter.format(8949.84f));
+ assertEquals("8.949856E+16", NumberFormatter.format(89498564737284944f));
+ assertEquals("-8.949856E+16", NumberFormatter.format(-89498564737284944f));
+ assertEquals("895649.9", NumberFormatter.format(895649.84737284944f));
+ assertEquals("300", NumberFormatter.format(300f));
+ assertEquals("-300", NumberFormatter.format(-300f));
+ assertEquals("0.3", NumberFormatter.format(0.3f));
+ assertEquals("0.1", NumberFormatter.format(0.1f));
+ assertEquals("2.342342E-12", NumberFormatter.format(0.0000000000023423421f));
+ assertEquals("2.342342E-11", NumberFormatter.format(0.000000000023423421f));
+ assertEquals("2.342342E-10", NumberFormatter.format(0.00000000023423421f));
+ assertEquals("-2.342342E-10", NumberFormatter.format(-0.00000000023423421f));
+ assertEquals("2.342342E-12", NumberFormatter.format(0.00000000000234234214f));
+ assertEquals("2.342342E-12", NumberFormatter.format(0.000000000002342342156f));
+ assertEquals("0.0000234", NumberFormatter.format(0.0000234f));
+ assertEquals("2.342E-05", NumberFormatter.format(0.00002342f));
+ assertEquals("1.#INF", NumberFormatter.format(Float.POSITIVE_INFINITY));
+ assertEquals("-1.#INF", NumberFormatter.format(Float.NEGATIVE_INFINITY));
+ assertEquals("1.#QNAN", NumberFormatter.format(Float.NaN));
+ }
+}
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
index e68ff33..981c4d3 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
@@ -26,7 +26,7 @@ import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.eval
*
* @author James Ahlborn
*/
-public class DefaultFunctionsTest extends TestCase
+public class DefaultFunctionsTest extends TestCase
{
public DefaultFunctionsTest(String name) {
@@ -75,12 +75,12 @@ public class DefaultFunctionsTest extends TestCase
eval("=CSng(\"57.12345\")"));
assertEquals("9786", eval("=CStr(9786)"));
assertEquals("-42", eval("=CStr(-42)"));
-
+
// FIXME, instr, instrrev
assertEquals("FOOO", eval("=UCase(\"fOoO\")"));
assertEquals("fooo", eval("=LCase(\"fOoO\")"));
-
+
assertEquals("bl", eval("=Left(\"blah\", 2)"));
assertEquals("", eval("=Left(\"blah\", 0)"));
assertEquals("blah", eval("=Left(\"blah\", 17)"));
@@ -94,104 +94,104 @@ public class DefaultFunctionsTest extends TestCase
public void testFinancialFuncs() throws Exception
{
- assertEquals("-9.578594039813165",
+ assertEquals("-9.57859403981317",
eval("=CStr(NPer(0.12/12,-100,-1000))"));
- assertEquals("-9.488095005505832",
+ assertEquals("-9.48809500550583",
eval("=CStr(NPer(0.12/12,-100,-1000,0,1))"));
- assertEquals("60.08212285376166",
+ assertEquals("60.0821228537617",
eval("=CStr(NPer(0.12/12,-100,-1000,10000))"));
- assertEquals("59.673865674294554",
+ assertEquals("59.6738656742946",
eval("=CStr(NPer(0.12/12,-100,-1000,10000,1))"));
- assertEquals("69.66071689357483",
+ assertEquals("69.6607168935748",
eval("=CStr(NPer(0.12/12,-100,0,10000))"));
- assertEquals("69.16196067980039",
+ assertEquals("69.1619606798004",
eval("=CStr(NPer(0.12/12,-100,0,10000,1))"));
- assertEquals("8166.966985640913",
+ assertEquals("8166.96698564091",
eval("=CStr(FV(0.12/12,60,-100))"));
- assertEquals("8248.636655497321",
+ assertEquals("8248.63665549732",
eval("=CStr(FV(0.12/12,60,-100,0,1))"));
- assertEquals("6350.270287076823",
+ assertEquals("6350.27028707682",
eval("=CStr(FV(0.12/12,60,-100,1000))"));
- assertEquals("6431.939956933231",
+ assertEquals("6431.93995693323",
eval("=CStr(FV(0.12/12,60,-100,1000,1))"));
- assertEquals("4495.503840622403",
+ assertEquals("4495.5038406224",
eval("=CStr(PV(0.12/12,60,-100))"));
- assertEquals("4540.458879028627",
+ assertEquals("4540.45887902863",
eval("=CStr(PV(0.12/12,60,-100,0,1))"));
- assertEquals("-1008.992318755193",
+ assertEquals("-1008.99231875519",
eval("=CStr(PV(0.12/12,60,-100,10000))"));
- assertEquals("-964.0372803489684",
+ assertEquals("-964.037280348968",
eval("=CStr(PV(0.12/12,60,-100,10000,1))"));
- assertEquals("22.24444768490176",
+ assertEquals("22.2444476849018",
eval("=CStr(Pmt(0.12/12,60,-1000))"));
- assertEquals("22.024205628615604",
+ assertEquals("22.0242056286156",
eval("=CStr(Pmt(0.12/12,60,-1000,0,1))"));
- assertEquals("-100.20002916411586",
+ assertEquals("-100.200029164116",
eval("=CStr(Pmt(0.12/12,60,-1000,10000))"));
- assertEquals("-99.20794966744144",
+ assertEquals("-99.2079496674414",
eval("=CStr(Pmt(0.12/12,60,-1000,10000,1))"));
- assertEquals("-122.44447684901762",
+ assertEquals("-122.444476849018",
eval("=CStr(Pmt(0.12/12,60,0,10000))"));
- assertEquals("-121.23215529605704",
+ assertEquals("-121.232155296057",
eval("=CStr(Pmt(0.12/12,60,0,10000,1))"));
// FIXME not working for all param combos
- // assertEquals("10.0",
+ // assertEquals("10.0",
// eval("=CStr(IPmt(0.12/12,1,60,-1000))"));
- // assertEquals("5.904184782975672",
+ // assertEquals("5.904184782975672",
// eval("=CStr(IPmt(0.12/12,30,60,-1000))"));
// 0
- // assertEquals("",
+ // assertEquals("",
// eval("=CStr(IPmt(0.12/12,1,60,-1000,0,1))"));
// 5.84572750...
- // assertEquals("5.845727507896704",
+ // assertEquals("5.845727507896704",
// eval("=CStr(IPmt(0.12/12,30,60,-1000,0,1))"));
// 0
- // assertEquals("",
+ // assertEquals("",
// eval("=CStr(IPmt(0.12/12,1,60,0,10000))"));
// 40.9581521702433
- // assertEquals("40.95815217024329",
+ // assertEquals("40.95815217024329",
// eval("=CStr(IPmt(0.12/12,30,60,0,10000))"));
// 0
- // assertEquals("",
+ // assertEquals("",
// eval("=CStr(IPmt(0.12/12,1,60,0,10000,1))"));
// 40.552625911132
- // assertEquals("40.55262591113197",
+ // assertEquals("40.55262591113197",
// eval("=CStr(IPmt(0.12/12,30,60,0,10000,1))"));
- // assertEquals("10.0",
+ // assertEquals("10.0",
// eval("=CStr(IPmt(0.12/12,1,60,-1000,10000))"));
- // assertEquals("46.862336953218964",
+ // assertEquals("46.862336953218964",
// eval("=CStr(IPmt(0.12/12,30,60,-1000,10000))"));
// 0
- // assertEquals("",
+ // assertEquals("",
// eval("=CStr(IPmt(0.12/12,1,60,-1000,10000,1))"));
// 46.3983534190287
- // assertEquals("46.39835341902867",
+ // assertEquals("46.39835341902867",
// eval("=CStr(IPmt(0.12/12,30,60,-1000,10000,1))"));
// FIXME, doesn't work for partial days
- // assertEquals("1.3150684931506849",
+ // assertEquals("1.3150684931506849",
// eval("=CStr(DDB(2400,300,10*365,1))"));
- // assertEquals("40.0",
+ // assertEquals("40.0",
// eval("=CStr(DDB(2400,300,10*12,1))"));
- // assertEquals("480.0",
+ // assertEquals("480.0",
// eval("=CStr(DDB(2400,300,10,1))"));
- // assertEquals("22.122547200000042",
+ // assertEquals("22.122547200000042",
// eval("=CStr(DDB(2400,300,10,10))"));
- // assertEquals("245.76",
+ // assertEquals("245.76",
// eval("=CStr(DDB(2400,300,10,4))"));
- // assertEquals("307.20000000000005",
+ // assertEquals("307.20000000000005",
// eval("=CStr(DDB(2400,300,10,3))"));
- // assertEquals("480.0",
+ // assertEquals("480.0",
// eval("=CStr(DDB(2400,300,10,0.1))"));
// 274.768033075174
- // assertEquals("",
+ // assertEquals("",
// eval("=CStr(DDB(2400,300,10,3.5))"));
-
+
}
}