From fc8a8d3e6273356ba795f647b38fc01f68727c1c Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Mon, 10 Aug 2015 16:19:24 -0700 Subject: BoundedRational.java cleanup Bug: 24811759 Bug: 21469726 Bug: 23080519 Reformat to 100 columns. Reformat simple if-statements and rename variables for better consistency with coding conventions. Switch many comments to javadoc style. Consistently use signum() to compare to zero. It's more concise and probably slightly more efficient. Change the asBigInteger implementation to use a single divideAndRemainder call instead of relying on gcd. Add tests. Eliminate redundant test in maybeReduce(). Change-Id: I4c275494e076612d09a05bc317c9972008619cda (cherry picked from commit a4511f349124ca9cd2a7f9cb742be02b832a0206) --- tests/src/com/android/calculator2/BRTest.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/src/com/android') diff --git a/tests/src/com/android/calculator2/BRTest.java b/tests/src/com/android/calculator2/BRTest.java index 77d4bf0..0163a0f 100644 --- a/tests/src/com/android/calculator2/BRTest.java +++ b/tests/src/com/android/calculator2/BRTest.java @@ -139,6 +139,12 @@ public class BRTest extends TestCase { check(BR_0.signum() == 0, "signum(0)"); check(BR_M1.signum() == -1, "signum(-1)"); check(BR_2.signum() == 1, "signum(2)"); + check(BoundedRational.asBigInteger(BR_390).intValue() == 390, "390.asBigInteger()"); + check(BoundedRational.asBigInteger(BoundedRational.HALF) == null, "1/2.asBigInteger()"); + check(BoundedRational.asBigInteger(BoundedRational.MINUS_HALF) == null, + "-1/2.asBigInteger()"); + check(BoundedRational.asBigInteger(new BoundedRational(15, -5)).intValue() == -3, + "-15/5.asBigInteger()"); check(BoundedRational.digitsRequired(BoundedRational.ZERO) == 0, "digitsRequired(0)"); check(BoundedRational.digitsRequired(BoundedRational.HALF) == 1, "digitsRequired(1/2)"); check(BoundedRational.digitsRequired(BoundedRational.MINUS_HALF) == 1, -- cgit v1.2.3