summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-10-11 16:51:57 (GMT)
committerAndroid Git Automerger <android-git-automerger@android.com>2015-10-11 16:51:57 (GMT)
commitdb3decfeae48651bc7b621be8a7539c0b360f8e1 (patch)
treef90f6d2177056828239dd136337a3b5807dd0e92
parent1ab460d222c7b5c6538de558bed465e2006218f2 (diff)
parentc07e2616582e85e859ddf77cfb0378b99199ffc7 (diff)
downloadandroid_packages_apps_ExactCalculator-db3decfeae48651bc7b621be8a7539c0b360f8e1.zip
android_packages_apps_ExactCalculator-db3decfeae48651bc7b621be8a7539c0b360f8e1.tar.gz
android_packages_apps_ExactCalculator-db3decfeae48651bc7b621be8a7539c0b360f8e1.tar.bz2
am c07e2616: am 6cccee27: Merge "Fix factorial(0)" into mnc-dr-dev
* commit 'c07e2616582e85e859ddf77cfb0378b99199ffc7': Fix factorial(0)
-rw-r--r--src/com/android/calculator2/BoundedRational.java3
-rw-r--r--tests/AndroidManifest.xml2
-rw-r--r--tests/README.txt2
-rw-r--r--tests/src/com/android/calculator2/BRTest.java4
4 files changed, 9 insertions, 2 deletions
diff --git a/src/com/android/calculator2/BoundedRational.java b/src/com/android/calculator2/BoundedRational.java
index 9d3e2a7..dc132f6 100644
--- a/src/com/android/calculator2/BoundedRational.java
+++ b/src/com/android/calculator2/BoundedRational.java
@@ -555,6 +555,9 @@ public class BoundedRational {
}
return prod1.multiply(prod2);
} else {
+ if (n == 0) {
+ return BigInteger.ONE;
+ }
BigInteger res = BigInteger.valueOf(n);
for (long i = n - step; i > 1; i -= step) {
res = res.multiply(BigInteger.valueOf(i));
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 62fe5c0..491603d 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -21,7 +21,7 @@
<instrumentation
android:name="android.test.InstrumentationTestRunner"
- android:targetPackage="com.android.exactcalculator"
+ android:targetPackage="com.android.calculator2"
android:label="BoundedRational and Calculator Functional Test" />
<application>
diff --git a/tests/README.txt b/tests/README.txt
index 304766f..bfe35ca 100644
--- a/tests/README.txt
+++ b/tests/README.txt
@@ -4,7 +4,7 @@ Run on Android with
2) Install the calculator with
adb install <tree root>/out/target/product/generic/data/app/ExactCalculator/ExactCalculator.apk
3) adb install <tree root>/out/target/product/generic/data/app/ExactCalculatorTests/ExactCalculatorTests.apk
-4) adb shell am instrument -w com.android.exactcalculator.tests/android.test.InstrumentationTestRunner
+4) adb shell am instrument -w com.android.calculator2.tests/android.test.InstrumentationTestRunner
There are three kinds of tests:
diff --git a/tests/src/com/android/calculator2/BRTest.java b/tests/src/com/android/calculator2/BRTest.java
index 0163a0f..68214d0 100644
--- a/tests/src/com/android/calculator2/BRTest.java
+++ b/tests/src/com/android/calculator2/BRTest.java
@@ -151,6 +151,10 @@ public class BRTest extends TestCase {
"digitsRequired(-1/2)");
check(BoundedRational.digitsRequired(new BoundedRational(1,-2)) == 1,
"digitsRequired(1/-2)");
+ check(BoundedRational.fact(BoundedRational.ZERO).equals(BoundedRational.ONE), "0!");
+ check(BoundedRational.fact(BoundedRational.ONE).equals(BoundedRational.ONE), "1!");
+ check(BoundedRational.fact(BoundedRational.TWO).equals(BoundedRational.TWO), "2!");
+ check(BoundedRational.fact(BR_15).equals(new BoundedRational(1307674368000L)), "15!");
// We check values that include all interesting degree values.
BoundedRational r = BR_M390;
while (!r.equals(BR_390)) {