summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-02-01 16:25:40 -0800
committerElliott Hughes <enh@google.com>2010-02-01 16:29:50 -0800
commit5c2b841724e903a06efdfb854bc2cd7c305728ed (patch)
treec9f16a40c570a756ee8954744e8829ee7a5e1627
parenta6dc264b8fc69427d54ba8da6bf8f36fd85ecf60 (diff)
downloadlibcore-5c2b841724e903a06efdfb854bc2cd7c305728ed.zip
libcore-5c2b841724e903a06efdfb854bc2cd7c305728ed.tar.gz
libcore-5c2b841724e903a06efdfb854bc2cd7c305728ed.tar.bz2
Fix BigDecimalTest.test_stripTrailingZero.
jessewilson reverted an upstream change (https://issues.apache.org/jira/browse/HARMONY-4623) that caused an RI incompatibility. Although it seems like the RI behavior is wrong, the poor design of BigDecimal.equals (which checks both value *and* scale) probably means we should remain compatible. This patch changes the test expectation to match the RI's behavior and adds a comment in both the code and its test explaining that this is deliberate.
-rw-r--r--math/src/main/java/java/math/BigDecimal.java3
-rw-r--r--math/src/test/java/tests/api/java/math/BigDecimalTest.java7
2 files changed, 7 insertions, 3 deletions
diff --git a/math/src/main/java/java/math/BigDecimal.java b/math/src/main/java/java/math/BigDecimal.java
index 33042ba..4e4875b 100644
--- a/math/src/main/java/java/math/BigDecimal.java
+++ b/math/src/main/java/java/math/BigDecimal.java
@@ -2148,7 +2148,10 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
long newScale = scale;
if (isZero()) {
+ // BEGIN android-changed: preserve RI compatibility, so BigDecimal.equals (which checks
+ // value *and* scale) continues to work.
return this;
+ // END android-changed
}
BigInteger strippedBI = getUnscaledValue();
BigInteger[] quotAndRem;
diff --git a/math/src/test/java/tests/api/java/math/BigDecimalTest.java b/math/src/test/java/tests/api/java/math/BigDecimalTest.java
index 572f2c1..29d68a2 100644
--- a/math/src/test/java/tests/api/java/math/BigDecimalTest.java
+++ b/math/src/test/java/tests/api/java/math/BigDecimalTest.java
@@ -1293,7 +1293,6 @@ public class BigDecimalTest extends junit.framework.TestCase {
method = "stripTrailingZeros",
args = {}
)
- @AndroidOnly("Stripping trailing zeroes from 0.000 value doesn't work on RI. See below")
public void test_stripTrailingZero() {
BigDecimal sixhundredtest = new BigDecimal("600.0");
assertTrue("stripTrailingZero failed for 600.0",
@@ -1306,11 +1305,13 @@ public class BigDecimalTest extends junit.framework.TestCase {
((notrailingzerotest.stripTrailingZeros()).scale() == 0)
);
+ // BEGIN android-changed: preserve RI compatibility, so BigDecimal.equals (which checks
+ // value *and* scale) continues to work. https://issues.apache.org/jira/browse/HARMONY-4623
/* Zero */
- //regression for HARMONY-4623, NON-BUG DIFF with RI
BigDecimal zerotest = new BigDecimal("0.0000");
assertEquals("stripTrailingZero failed for 0.0000",
- 0, (zerotest.stripTrailingZeros()).scale() );
+ 4, (zerotest.stripTrailingZeros()).scale() );
+ // END android-changed
}
@TestTargetNew(