diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2024-02-03 18:17:33 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2024-02-03 18:17:33 +0000 |
commit | 672387c5a4499e6c104a1c09dc845a5cdb6c62f1 (patch) | |
tree | 9e4b3e0cb3d7f1d2661e59187bead4feb7e4ed61 /src/test/java/com/healthmarketscience/jackcess | |
parent | 19ee157d4a7f8f26ed4950eb18d14721c54bb1a5 (diff) | |
download | jackcess-672387c5a4499e6c104a1c09dc845a5cdb6c62f1.tar.gz jackcess-672387c5a4499e6c104a1c09dc845a5cdb6c62f1.zip |
fix NumberFormatter so that it formats according to the locale of the current db
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1406 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience/jackcess')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java | 13 | ||||
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java | 121 |
2 files changed, 75 insertions, 59 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java index 67ad20b..ccdf087 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java @@ -580,37 +580,45 @@ public class ExpressionatorTest extends TestCase _thisVal = thisVal; } + @Override public Value.Type getResultType() { return null; } + @Override public TemporalConfig getTemporalConfig() { return TemporalConfig.US_TEMPORAL_CONFIG; } + @Override public DateTimeFormatter createDateFormatter(String formatStr) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern( formatStr, TemporalConfig.US_TEMPORAL_CONFIG.getLocale()); return dtf; } + @Override public ZoneId getZoneId() { return TestUtil.TEST_TZ.toZoneId(); } + @Override public NumericConfig getNumericConfig() { return NumericConfig.US_NUMERIC_CONFIG; } + @Override public DecimalFormat createDecimalFormat(String formatStr) { return new DecimalFormat( formatStr, NumericConfig.US_NUMERIC_CONFIG.getDecimalFormatSymbols()); } + @Override public FunctionLookup getFunctionLookup() { return DefaultFunctions.LOOKUP; } + @Override public Value getThisColumnValue() { if(_thisVal == null) { throw new UnsupportedOperationException(); @@ -618,22 +626,27 @@ public class ExpressionatorTest extends TestCase return _thisVal; } + @Override public Value getIdentifierValue(Identifier identifier) { throw new UnsupportedOperationException(); } + @Override public float getRandom(Integer seed) { return _rndCtx.getRandom(seed); } + @Override public Bindings getBindings() { return _bindings; } + @Override public Object get(String key) { return _bindings.get(key); } + @Override public void put(String key, Object value) { _bindings.put(key, value); } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java index acc2a1a..11a0adf 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java @@ -18,6 +18,7 @@ package com.healthmarketscience.jackcess.impl.expr; import java.math.BigDecimal; +import com.healthmarketscience.jackcess.expr.NumericConfig; import static junit.framework.TestCase.assertEquals; import org.junit.Test; @@ -27,78 +28,80 @@ import org.junit.Test; */ public class NumberFormatterTest { + private NumberFormatter _numFmt = new NumberFormatter( + NumericConfig.US_NUMERIC_CONFIG.getDecimalFormatSymbols()); @Test 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)); + assertEquals("894984737284944", _numFmt.format(894984737284944d)); + assertEquals("-894984737284944", _numFmt.format(-894984737284944d)); + assertEquals("8949.84737284944", _numFmt.format(8949.84737284944d)); + assertEquals("8949847372844", _numFmt.format(8949847372844d)); + assertEquals("8949.847384944", _numFmt.format(8949.847384944d)); + assertEquals("8.94985647372849E+16", _numFmt.format(89498564737284944d)); + assertEquals("-8.94985647372849E+16", _numFmt.format(-89498564737284944d)); + assertEquals("895649.847372849", _numFmt.format(895649.84737284944d)); + assertEquals("300", _numFmt.format(300d)); + assertEquals("-300", _numFmt.format(-300d)); + assertEquals("0.3", _numFmt.format(0.3d)); + assertEquals("0.1", _numFmt.format(0.1d)); + assertEquals("2.3423421E-12", _numFmt.format(0.0000000000023423421d)); + assertEquals("2.3423421E-11", _numFmt.format(0.000000000023423421d)); + assertEquals("2.3423421E-10", _numFmt.format(0.00000000023423421d)); + assertEquals("-2.3423421E-10", _numFmt.format(-0.00000000023423421d)); + assertEquals("2.34234214E-12", _numFmt.format(0.00000000000234234214d)); + assertEquals("2.342342156E-12", _numFmt.format(0.000000000002342342156d)); + assertEquals("0.000000023423421", _numFmt.format(0.000000023423421d)); + assertEquals("2.342342133E-07", _numFmt.format(0.0000002342342133d)); + assertEquals("1.#INF", _numFmt.format(Double.POSITIVE_INFINITY)); + assertEquals("-1.#INF", _numFmt.format(Double.NEGATIVE_INFINITY)); + assertEquals("1.#QNAN", _numFmt.format(Double.NaN)); } @Test 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)); + assertEquals("8949847", _numFmt.format(8949847f)); + assertEquals("-8949847", _numFmt.format(-8949847f)); + assertEquals("8949.847", _numFmt.format(8949.847f)); + assertEquals("894984", _numFmt.format(894984f)); + assertEquals("8949.84", _numFmt.format(8949.84f)); + assertEquals("8.949856E+16", _numFmt.format(89498564737284944f)); + assertEquals("-8.949856E+16", _numFmt.format(-89498564737284944f)); + assertEquals("895649.9", _numFmt.format(895649.84737284944f)); + assertEquals("300", _numFmt.format(300f)); + assertEquals("-300", _numFmt.format(-300f)); + assertEquals("0.3", _numFmt.format(0.3f)); + assertEquals("0.1", _numFmt.format(0.1f)); + assertEquals("2.342342E-12", _numFmt.format(0.0000000000023423421f)); + assertEquals("2.342342E-11", _numFmt.format(0.000000000023423421f)); + assertEquals("2.342342E-10", _numFmt.format(0.00000000023423421f)); + assertEquals("-2.342342E-10", _numFmt.format(-0.00000000023423421f)); + assertEquals("2.342342E-12", _numFmt.format(0.00000000000234234214f)); + assertEquals("2.342342E-12", _numFmt.format(0.000000000002342342156f)); + assertEquals("0.0000234", _numFmt.format(0.0000234f)); + assertEquals("2.342E-05", _numFmt.format(0.00002342f)); + assertEquals("1.#INF", _numFmt.format(Float.POSITIVE_INFINITY)); + assertEquals("-1.#INF", _numFmt.format(Float.NEGATIVE_INFINITY)); + assertEquals("1.#QNAN", _numFmt.format(Float.NaN)); } @Test public void testDecimalFormat() throws Exception { - assertEquals("9874539485972.2342342234234", NumberFormatter.format(new BigDecimal("9874539485972.2342342234234"))); - assertEquals("9874539485972.234234223423468", NumberFormatter.format(new BigDecimal("9874539485972.2342342234234678"))); - assertEquals("-9874539485972.234234223423468", NumberFormatter.format(new BigDecimal("-9874539485972.2342342234234678"))); - assertEquals("9.874539485972234234223423468E+31", NumberFormatter.format(new BigDecimal("98745394859722342342234234678000"))); - assertEquals("9.874539485972234234223423468E+31", NumberFormatter.format(new BigDecimal("98745394859722342342234234678000"))); - assertEquals("-9.874539485972234234223423468E+31", NumberFormatter.format(new BigDecimal("-98745394859722342342234234678000"))); - assertEquals("300", NumberFormatter.format(new BigDecimal("300.0"))); - assertEquals("-300", NumberFormatter.format(new BigDecimal("-300.000"))); - assertEquals("0.3", NumberFormatter.format(new BigDecimal("0.3"))); - assertEquals("0.1", NumberFormatter.format(new BigDecimal("0.1000"))); - assertEquals("0.0000000000023423428930458", NumberFormatter.format(new BigDecimal("0.0000000000023423428930458"))); - assertEquals("2.3423428930458389038451E-12", NumberFormatter.format(new BigDecimal("0.0000000000023423428930458389038451"))); - assertEquals("2.342342893045838903845134766E-12", NumberFormatter.format(new BigDecimal("0.0000000000023423428930458389038451347656"))); + assertEquals("9874539485972.2342342234234", _numFmt.format(new BigDecimal("9874539485972.2342342234234"))); + assertEquals("9874539485972.234234223423468", _numFmt.format(new BigDecimal("9874539485972.2342342234234678"))); + assertEquals("-9874539485972.234234223423468", _numFmt.format(new BigDecimal("-9874539485972.2342342234234678"))); + assertEquals("9.874539485972234234223423468E+31", _numFmt.format(new BigDecimal("98745394859722342342234234678000"))); + assertEquals("9.874539485972234234223423468E+31", _numFmt.format(new BigDecimal("98745394859722342342234234678000"))); + assertEquals("-9.874539485972234234223423468E+31", _numFmt.format(new BigDecimal("-98745394859722342342234234678000"))); + assertEquals("300", _numFmt.format(new BigDecimal("300.0"))); + assertEquals("-300", _numFmt.format(new BigDecimal("-300.000"))); + assertEquals("0.3", _numFmt.format(new BigDecimal("0.3"))); + assertEquals("0.1", _numFmt.format(new BigDecimal("0.1000"))); + assertEquals("0.0000000000023423428930458", _numFmt.format(new BigDecimal("0.0000000000023423428930458"))); + assertEquals("2.3423428930458389038451E-12", _numFmt.format(new BigDecimal("0.0000000000023423428930458389038451"))); + assertEquals("2.342342893045838903845134766E-12", _numFmt.format(new BigDecimal("0.0000000000023423428930458389038451347656"))); } } |