summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.mk13
-rw-r--r--tests/AndroidManifest.xml31
-rw-r--r--tests/README.txt48
-rw-r--r--tests/src/com/android/calculator2/BoundedRationalTest.java157
-rw-r--r--tests/src/com/android/calculator2/CalculatorHitSomeButtons.java179
-rw-r--r--tests/src/com/android/calculator2/EvaluatorTest.java59
-rw-r--r--tests/src/com/android/calculator2/UnifiedRealTest.java264
7 files changed, 0 insertions, 751 deletions
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index 8a84600..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_PACKAGE_NAME := ExactCalculatorTests
-LOCAL_INSTRUMENTATION_FOR := ExactCalculator
-
-LOCAL_SDK_VERSION := current
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
deleted file mode 100644
index 491603d..0000000
--- a/tests/AndroidManifest.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 The Android Open Source Project
-
- 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.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.calculator2.tests">
-
- <uses-sdk android:minSdkVersion="21" />
-
- <instrumentation
- android:name="android.test.InstrumentationTestRunner"
- android:targetPackage="com.android.calculator2"
- android:label="BoundedRational and Calculator Functional Test" />
-
- <application>
- <uses-library android:name="android.test.runner" />
- </application>
-
-</manifest>
diff --git a/tests/README.txt b/tests/README.txt
deleted file mode 100644
index bfe35ca..0000000
--- a/tests/README.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-Run on Android with
-
-1) Build the tests.
-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.calculator2.tests/android.test.InstrumentationTestRunner
-
-There are three kinds of tests:
-
-1. A superficial test of calculator functionality through the UI.
-This is a resurrected version of a test that appeared in KitKat.
-This is currently only a placeholder for regression tests we shouldn't
-forget; it doesn't yet actually do much of anything.
-
-2. A test of the BoundedRationals library that mostly checks for agreement
-with the constructive reals (CR) package. (The BoundedRationals package
-is used by the calculator mostly to identify exact results, i.e.
-terminating decimal expansions. But it's also used to optimize CR
-computations, and bugs in BoundedRational could result in incorrect
-outputs.)
-
-3. A quick test of Evaluator.testUnflipZeroes(), which we do not know how to
-test manually.
-
-We currently have no automatic tests for display formatting corner cases.
-The following numbers have exhibited problems in the past and would be good
-to test. Some of them are difficult to test automatically, because they
-require scrolling to both ends of the result. For those with finite
-decimal expansions, it also worth confirming that the "display with leading
-digits" display shows an exact value when scrolled all the way to the right.
-
-Some interesting manual test cases:
-
-10^10 + 10^30
-10^30 + 10^-10
--10^30 + 20
-10^30 + 10^-30
--10^30 - 10^10
--1.2x10^-9
--1.2x10^-8
--1.2x10^-10
--10^-12
-1 - 10^-98
-1 - 10^-100
-1 - 10^-300
-1/-56x10^18 (on a Nexus 7 sized portrait display)
--10^-500 (scroll to see the 1, then scroll back & verify minus sign appears)
diff --git a/tests/src/com/android/calculator2/BoundedRationalTest.java b/tests/src/com/android/calculator2/BoundedRationalTest.java
deleted file mode 100644
index a53d6ad..0000000
--- a/tests/src/com/android/calculator2/BoundedRationalTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * 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.
- */
-
-// A test for BoundedRationals package.
-
-package com.android.calculator2;
-
-import com.hp.creals.CR;
-import com.hp.creals.UnaryCRFunction;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import java.math.BigInteger;
-
-public class BoundedRationalTest extends TestCase {
- private static void check(boolean x, String s) {
- if (!x) throw new AssertionFailedError(s);
- }
- final static int TEST_PREC = -100; // 100 bits to the right of
- // binary point.
- private static void checkEq(BoundedRational x, CR y, String s) {
- check(x.crValue().compareTo(y, TEST_PREC) == 0, s);
- }
- private static void checkWeakEq(BoundedRational x, CR y, String s) {
- if (x != null) checkEq(x, y, s);
- }
-
- private final static BoundedRational BR_0 = new BoundedRational(0);
- private final static BoundedRational BR_M1 = new BoundedRational(-1);
- private final static BoundedRational BR_2 = new BoundedRational(2);
- private final static BoundedRational BR_M2 = new BoundedRational(-2);
- private final static BoundedRational BR_15 = new BoundedRational(15);
- private final static BoundedRational BR_390 = new BoundedRational(390);
- private final static BoundedRational BR_M390 = new BoundedRational(-390);
- private final static CR CR_1 = CR.valueOf(1);
-
- // We assume that x is simple enough that we don't overflow bounds.
- private static void checkBR(BoundedRational x) {
- check(x != null, "test data should not be null");
- CR xAsCR = x.crValue();
- checkEq(BoundedRational.add(x, BoundedRational.ONE), xAsCR.add(CR_1),
- "add 1:" + x);
- checkEq(BoundedRational.subtract(x, BoundedRational.MINUS_THIRTY),
- xAsCR.subtract(CR.valueOf(-30)), "sub -30:" + x);
- checkEq(BoundedRational.multiply(x, BR_15),
- xAsCR.multiply(CR.valueOf(15)), "multiply 15:" + x);
- checkEq(BoundedRational.divide(x, BR_15),
- xAsCR.divide(CR.valueOf(15)), "divide 15:" + x);
- BigInteger big_x = BoundedRational.asBigInteger(x);
- long long_x = (big_x == null? 0 : big_x.longValue());
- if (x.compareTo(BoundedRational.THIRTY) <= 0
- && x.compareTo(BoundedRational.MINUS_THIRTY) >= 0) {
- checkWeakEq(BoundedRational.pow(BR_15, x),
- CR.valueOf(15).ln().multiply(xAsCR).exp(),
- "pow(15,x):" + x);
- }
- if (x.signum() > 0) {
- checkWeakEq(BoundedRational.sqrt(x), xAsCR.sqrt(), "sqrt:" + x);
- checkEq(BoundedRational.pow(x, BR_15),
- xAsCR.ln().multiply(CR.valueOf(15)).exp(),
- "pow(x,15):" + x);
- }
- }
-
- public void testBR() {
- BoundedRational b = new BoundedRational(4,-6);
- check(b.toString().equals("4/-6"), "toString(4/-6)");
- check(b.toNiceString().equals("-2/3"), "toNiceString(4/-6)");
- check(b.toStringTruncated(1).equals("-0.6"), "(4/-6).toStringT(1)");
- check(BR_15.toStringTruncated(0).equals("15."), "15.toStringT(1)");
- check(BR_0.toStringTruncated(2).equals("0.00"), "0.toStringT(2)");
- checkEq(BR_0, CR.valueOf(0), "0");
- checkEq(BR_390, CR.valueOf(390), "390");
- checkEq(BR_15, CR.valueOf(15), "15");
- checkEq(BR_M390, CR.valueOf(-390), "-390");
- checkEq(BR_M1, CR.valueOf(-1), "-1");
- checkEq(BR_2, CR.valueOf(2), "2");
- checkEq(BR_M2, CR.valueOf(-2), "-2");
- 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,
- "digitsRequired(-1/2)");
- check(BoundedRational.digitsRequired(new BoundedRational(1,-2)) == 1,
- "digitsRequired(1/-2)");
- // We check values that include all interesting degree values.
- BoundedRational r = BR_M390;
- while (!r.equals(BR_390)) {
- check(r != null, "loop counter overflowed!");
- checkBR(r);
- r = BoundedRational.add(r, BR_15);
- }
- checkBR(BoundedRational.HALF);
- checkBR(BoundedRational.MINUS_HALF);
- checkBR(BoundedRational.ONE);
- checkBR(BoundedRational.MINUS_ONE);
- checkBR(new BoundedRational(1000));
- checkBR(new BoundedRational(100));
- checkBR(new BoundedRational(4,9));
- check(BoundedRational.sqrt(new BoundedRational(4,9)) != null,
- "sqrt(4/9) is null");
- checkBR(BoundedRational.negate(new BoundedRational(4,9)));
- checkBR(new BoundedRational(5,9));
- checkBR(new BoundedRational(5,10));
- checkBR(new BoundedRational(5,10));
- checkBR(new BoundedRational(4,13));
- checkBR(new BoundedRational(36));
- checkBR(BoundedRational.negate(new BoundedRational(36)));
- check(BoundedRational.pow(null, BR_15) == null, "pow(null, 15)");
- }
-
- public void testBRexceptions() {
- try {
- BoundedRational.divide(BR_390, BoundedRational.ZERO);
- check(false, "390/0");
- } catch (ArithmeticException ignored) {}
- try {
- BoundedRational.sqrt(BR_M1);
- check(false, "sqrt(-1)");
- } catch (ArithmeticException ignored) {}
- }
-
- public void testBROverflow() {
- BoundedRational sum = new BoundedRational(0);
- long i;
- for (i = 1; i < 4000; ++i) {
- sum = BoundedRational.add(sum,
- BoundedRational.inverse(new BoundedRational(i)));
- if (sum == null) break;
- }
- // With MAX_SIZE = 10000, we seem to overflow at 3488.
- check(i > 3000, "Harmonic series overflowed at " + i);
- check(i < 4000, "Harmonic series didn't overflow");
- }
-}
diff --git a/tests/src/com/android/calculator2/CalculatorHitSomeButtons.java b/tests/src/com/android/calculator2/CalculatorHitSomeButtons.java
deleted file mode 100644
index a075a64..0000000
--- a/tests/src/com/android/calculator2/CalculatorHitSomeButtons.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
- * Copyright (c) 2008, Google Inc.
- *
- * 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.android.calculator2;
-
-import android.app.Activity;
-import android.app.Instrumentation;
-import android.app.Instrumentation.ActivityMonitor;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.test.ActivityInstrumentationTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.View;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-import android.graphics.Rect;
-import android.test.TouchUtils;
-
-import com.android.calculator2.Calculator;
-import com.android.calculator2.R;
-import com.android.calculator2.CalculatorResult;
-
-/**
- * Instrumentation tests for poking some buttons
- *
- */
-
-public class CalculatorHitSomeButtons extends ActivityInstrumentationTestCase <Calculator>{
- public boolean setup = false;
- private static final String TAG = "CalculatorTests";
- Calculator mActivity = null;
- Instrumentation mInst = null;
-
- public CalculatorHitSomeButtons() {
- super("com.android.calculator2", Calculator.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- mActivity = getActivity();
- mInst = getInstrumentation();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-
- @LargeTest
- public void testPressSomeKeys() {
- Log.v(TAG, "Pressing some keys!");
-
- // Make sure that we clear the output
- press(KeyEvent.KEYCODE_ENTER);
- press(KeyEvent.KEYCODE_CLEAR);
-
- // 3 + 4 * 5 => 23
- press(KeyEvent.KEYCODE_3);
- press(KeyEvent.KEYCODE_PLUS);
- press(KeyEvent.KEYCODE_4);
- press(KeyEvent.KEYCODE_9 | KeyEvent.META_SHIFT_ON);
- press(KeyEvent.KEYCODE_5);
- press(KeyEvent.KEYCODE_ENTER);
-
- checkDisplay("23");
- }
-
-
- @LargeTest
- public void testTapSomeButtons() {
- // TODO: This probably makes way too many hardcoded assumptions about locale.
- // The calculator will need a routine to internationalize the output.
- // We should use that here, too.
- Log.v(TAG, "Tapping some buttons!");
-
- // Make sure that we clear the output
- tap(R.id.eq);
- tap(R.id.del);
-
- // 567 / 3 => 189
- tap(R.id.digit_5);
- tap(R.id.digit_6);
- tap(R.id.digit_7);
- tap(R.id.op_div);
- tap(R.id.digit_3);
- tap(R.id.dec_point);
- tap(R.id.eq);
-
- checkDisplay("189");
-
- // make sure we can continue calculations also
- // 189 - 789 => -600
- tap(R.id.op_sub);
- tap(R.id.digit_7);
- tap(R.id.digit_8);
- tap(R.id.digit_9);
- tap(R.id.eq);
-
- // Careful: the first digit in the expected value is \u2212, not "-" (a hyphen)
- checkDisplay(mActivity.getString(R.string.op_sub) + "600");
-
- tap(R.id.dec_point);
- tap(R.id.digit_5);
- tap(R.id.op_add);
- tap(R.id.dec_point);
- tap(R.id.digit_5);
- tap(R.id.eq);
- checkDisplay("1");
-
- tap(R.id.digit_5);
- tap(R.id.op_div);
- tap(R.id.digit_3);
- tap(R.id.dec_point);
- tap(R.id.digit_5);
- tap(R.id.op_mul);
- tap(R.id.digit_7);
- tap(R.id.eq);
- checkDisplay("10");
- }
-
- // helper functions
- private void press(int keycode) {
- mInst.sendKeyDownUpSync(keycode);
- }
-
- private void tap(int id) {
- View view = mActivity.findViewById(id);
- assertNotNull(view);
- TouchUtils.clickView(this, view);
- }
-
- private void checkDisplay(final String s) {
- /*
- FIXME: This doesn't yet work.
- try {
- Thread.sleep(20);
- runTestOnUiThread(new Runnable () {
- @Override
- public void run() {
- Log.v(TAG, "Display:" + displayVal());
- assertEquals(s, displayVal());
- }
- });
- } catch (Throwable e) {
- fail("unexpected exception" + e);
- }
- */
- }
-
- private String displayVal() {
- CalculatorResult display = (CalculatorResult) mActivity.findViewById(R.id.result);
- assertNotNull(display);
-
- TextView box = (TextView) display;
- assertNotNull(box);
-
- return box.getText().toString();
- }
-}
-
diff --git a/tests/src/com/android/calculator2/EvaluatorTest.java b/tests/src/com/android/calculator2/EvaluatorTest.java
deleted file mode 100644
index 307aef2..0000000
--- a/tests/src/com/android/calculator2/EvaluatorTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * 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.android.calculator2;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-/**
- * A test for a few static methods in Evaluator.
- * The most interesting one is for unflipZeroes(), which we don't know how to test with
- * real calculator input.
- */
-public class EvaluatorTest extends TestCase {
- private static void check(boolean x, String s) {
- if (!x) throw new AssertionFailedError(s);
- }
- public void testUnflipZeroes() {
- check(Evaluator.unflipZeroes("9.99", 2, "9.998", 3).equals("9.998"), "test 1");
- check(Evaluator.unflipZeroes("9.99", 2, "10.0000", 4).equals("9.9999"), "test 2");
- check(Evaluator.unflipZeroes("0.99", 2, "1.00000", 5).equals("0.99999"), "test 3");
- check(Evaluator.unflipZeroes("0.99", 2, "1.00", 2).equals("0.99"), "test 4");
- check(Evaluator.unflipZeroes("10.00", 2, "9.9999", 4).equals("9.9999"), "test 5");
- check(Evaluator.unflipZeroes("-10.00", 2, "-9.9999", 4).equals("-9.9999"), "test 6");
- check(Evaluator.unflipZeroes("-0.99", 2, "-1.00000000000000", 14)
- .equals("-0.99999999999999"), "test 7");
- check(Evaluator.unflipZeroes("12349.99", 2, "12350.00000", 5).equals("12349.99999"),
- "test 8");
- check(Evaluator.unflipZeroes("123.4999", 4, "123.5000000", 7).equals("123.4999999"),
- "test 9");
- }
-
- public void testGetMsdIndexOf() {
- check(Evaluator.getMsdIndexOf("-0.0234") == 4, "getMsdIndexOf(-0.0234)");
- check(Evaluator.getMsdIndexOf("23.45") == 0, "getMsdIndexOf(23.45)");
- check(Evaluator.getMsdIndexOf("-0.01") == Evaluator.INVALID_MSD, "getMsdIndexOf(-0.01)");
- }
-
- public void testExponentEnd() {
- check(Evaluator.exponentEnd("xE-2%3", 1) == 4, "exponentEnd(xE-2%3)");
- check(Evaluator.exponentEnd("xE+2%3", 1) == 1, "exponentEnd(xE+2%3)");
- check(Evaluator.exponentEnd("xe2%3", 1) == 1, "exponentEnd(xe2%3)");
- check(Evaluator.exponentEnd("xE123%3", 1) == 5, "exponentEnd(xE123%3)");
- check(Evaluator.exponentEnd("xE123456789%3", 1) == 1, "exponentEnd(xE123456789%3)");
- }
-}
diff --git a/tests/src/com/android/calculator2/UnifiedRealTest.java b/tests/src/com/android/calculator2/UnifiedRealTest.java
deleted file mode 100644
index 20ac2b1..0000000
--- a/tests/src/com/android/calculator2/UnifiedRealTest.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * 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.
- */
-
-// A test for UnifiedReal package.
-
-package com.android.calculator2;
-
-import com.hp.creals.CR;
-import com.hp.creals.UnaryCRFunction;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import java.math.BigInteger;
-
-public class UnifiedRealTest extends TestCase {
- private static void check(boolean x, String s) {
- if (!x) throw new AssertionFailedError(s);
- }
- final static int TEST_PREC = -100; // 100 bits to the right of
- // binary point.
- private static void checkEq(UnifiedReal x, CR y, String s) {
- check(x.crValue().compareTo(y, TEST_PREC) == 0, s);
- }
-
- private final static UnaryCRFunction ASIN = UnaryCRFunction.asinFunction;
- private final static UnaryCRFunction ACOS = UnaryCRFunction.acosFunction;
- private final static UnaryCRFunction ATAN = UnaryCRFunction.atanFunction;
- private final static UnaryCRFunction TAN = UnaryCRFunction.tanFunction;
- private final static CR CR_1 = CR.ONE;
-
- private final static CR RADIANS_PER_DEGREE = CR.PI.divide(CR.valueOf(180));
- private final static CR DEGREES_PER_RADIAN = CR.valueOf(180).divide(CR.PI);
- private final static CR LN10 = CR.valueOf(10).ln();
-
- private final static UnifiedReal UR_30 = new UnifiedReal(30);
- private final static UnifiedReal UR_MINUS30 = new UnifiedReal(-30);
- private final static UnifiedReal UR_15 = new UnifiedReal(15);
- private final static UnifiedReal UR_MINUS15 = new UnifiedReal(-15);
-
- private static CR toRadians(CR x) {
- return x.multiply(RADIANS_PER_DEGREE);
- }
-
- private static CR fromRadians(CR x) {
- return x.multiply(DEGREES_PER_RADIAN);
- }
-
- private static UnifiedReal toRadians(UnifiedReal x) {
- return x.multiply(UnifiedReal.RADIANS_PER_DEGREE);
- }
-
- private static UnifiedReal fromRadians(UnifiedReal x) {
- return x.divide(UnifiedReal.RADIANS_PER_DEGREE);
- }
-
- // We assume that x is simple enough that we don't overflow bounds.
- private static void checkUR(UnifiedReal x) {
- CR xAsCr = x.crValue();
- checkEq(x.add(UnifiedReal.ONE), xAsCr.add(CR_1), "add 1:" + x);
- checkEq(x.subtract(UR_MINUS30), xAsCr.subtract(CR.valueOf(-30)), "sub -30:" + x);
- checkEq(x.multiply(UR_15), xAsCr.multiply(CR.valueOf(15)), "multiply 15:" + x);
- checkEq(x.divide(UR_15), xAsCr.divide(CR.valueOf(15)), "divide 15:" + x);
- checkEq(x.sin(), xAsCr.sin(), "sin:" + x);
- checkEq(x.cos(), xAsCr.cos(), "cos:" + x);
- if (x.cos().definitelyNonZero()) {
- checkEq(x.tan(), TAN.execute(xAsCr), "tan:" + x);
- }
- checkEq(toRadians(x).sin(), toRadians(xAsCr).sin(), "degree sin:" + x);
- checkEq(toRadians(x).cos(), toRadians(xAsCr).cos(), "degree cos:" + x);
- BigInteger big_x = x.bigIntegerValue();
- long long_x = (big_x == null? 0 : big_x.longValue());
- try {
- checkEq(toRadians(x).tan(), TAN.execute(toRadians(xAsCr)), "degree tan:" + x);
- check((long_x - 90) % 180 != 0, "missed undefined tan: " + x);
- } catch (ArithmeticException ignored) {
- check((long_x - 90) % 180 == 0, "exception on defined tan: " + x + " " + ignored);
- }
- if (x.compareTo(UR_30) <= 0 && x.compareTo(UR_MINUS30) >= 0) {
- checkEq(x.exp(), xAsCr.exp(), "exp:" + x);
- checkEq(UR_15.pow(x), CR.valueOf(15).ln().multiply(xAsCr).exp(), "pow(15,x):" + x); }
- if (x.compareTo(UnifiedReal.ONE) <= 0
- && x.compareTo(UnifiedReal.ONE.negate()) >= 0) {
- checkEq(x.asin(), ASIN.execute(xAsCr), "asin:" + x);
- checkEq(x.acos(), ACOS.execute(xAsCr), "acos:" + x);
- checkEq(fromRadians(x.asin()), fromRadians(ASIN.execute(xAsCr)), "degree asin:" + x);
- checkEq(fromRadians(x.acos()), fromRadians(ACOS.execute(xAsCr)), "degree acos:" + x);
- }
- checkEq(x.atan(), ATAN.execute(xAsCr), "atan:" + x);
- if (x.signum() > 0) {
- checkEq(x.ln(), xAsCr.ln(), "ln:" + x);
- checkEq(x.sqrt(), xAsCr.sqrt(), "sqrt:" + x);
- checkEq(x.pow(UR_15), xAsCr.ln().multiply(CR.valueOf(15)).exp(), "pow(x,15):" + x);
- }
- }
-
- public void testUR() {
- UnifiedReal b = new UnifiedReal(new BoundedRational(4,-6));
- check(b.toString().equals("4/-6*1.0000000000"), "toString(4/-6)");
- check(b.toNiceString().equals("-2/3"), "toNiceString(4/-6)");
- check(b.toStringTruncated(1).equals("-0.6"), "(4/-6).toString(1)");
- check(UR_15.toStringTruncated(0).equals("15."), "15.toString(1)");
- check(UnifiedReal.ZERO.toStringTruncated(2).equals("0.00"), "0.toString(2)");
- checkEq(UnifiedReal.ZERO, CR.valueOf(0), "0");
- checkEq(new UnifiedReal(390), CR.valueOf(390), "390");
- checkEq(UR_15, CR.valueOf(15), "15");
- checkEq(new UnifiedReal(390).negate(), CR.valueOf(-390), "-390");
- checkEq(UnifiedReal.ONE.negate(), CR.valueOf(-1), "-1");
- checkEq(new UnifiedReal(2), CR.valueOf(2), "2");
- checkEq(new UnifiedReal(-2), CR.valueOf(-2), "-2");
- check(UnifiedReal.ZERO.signum() == 0, "signum(0)");
- check(UnifiedReal.ZERO.definitelyZero(), "definitelyZero(0)");
- check(!UnifiedReal.ZERO.definitelyNonZero(), "definitelyNonZero(0)");
- check(!UnifiedReal.PI.definitelyZero(), "definitelyZero(pi)");
- check(UnifiedReal.PI.definitelyNonZero(), "definitelyNonZero(pi)");
- check(UnifiedReal.ONE.negate().signum() == -1, "signum(-1)");
- check(new UnifiedReal(2).signum() == 1, "signum(2)");
- check(UnifiedReal.E.signum() == 1, "signum(e)");
- check(new UnifiedReal(400).bigIntegerValue().intValue() == 400, "400.bigIntegerValue()");
- check(UnifiedReal.HALF.bigIntegerValue() == null, "1/2.bigIntegerValue()");
- check(UnifiedReal.HALF.negate().bigIntegerValue() == null, "-1/2.bigIntegerValue()");
- check(new UnifiedReal(new BoundedRational(15, -5)).bigIntegerValue().intValue() == -3,
- "-15/5.asBigInteger()");
- check(UnifiedReal.ZERO.digitsRequired() == 0, "digitsRequired(0)");
- check(UnifiedReal.HALF.digitsRequired() == 1, "digitsRequired(1)");
- check(UnifiedReal.HALF.negate().digitsRequired() == 1, "digitsRequired(-1)");
- check(UnifiedReal.ONE.divide(new UnifiedReal(-2)).digitsRequired() == 1,
- "digitsRequired(-2)");
- check(UnifiedReal.ZERO.fact().definitelyEquals(UnifiedReal.ONE), "0!");
- check(UnifiedReal.ONE.fact().definitelyEquals(UnifiedReal.ONE), "1!");
- check(UnifiedReal.TWO.fact().definitelyEquals(UnifiedReal.TWO), "2!");
- check(new UnifiedReal(15).fact().definitelyEquals(new UnifiedReal(1307674368000L)), "15!");
- check(UnifiedReal.ONE.exactlyDisplayable(), "1 displayable");
- check(UnifiedReal.PI.exactlyDisplayable(), "PI displayable");
- check(UnifiedReal.E.exactlyDisplayable(), "E displayable");
- check(UnifiedReal.E.divide(UnifiedReal.E).exactlyDisplayable(), "E/E displayable");
- check(!UnifiedReal.E.divide(UnifiedReal.PI).exactlyDisplayable(), "!E/PI displayable");
- UnifiedReal r = new UnifiedReal(9).multiply(new UnifiedReal(3).sqrt()).ln();
- checkEq(r, CR.valueOf(9).multiply(CR.valueOf(3).sqrt()).ln(), "ln(9sqrt(3))");
- check(r.exactlyDisplayable(), "5/2log3");
- checkEq(r.exp(), CR.valueOf(9).multiply(CR.valueOf(3).sqrt()), "9sqrt(3)");
- check(r.exp().exactlyDisplayable(), "9sqrt(3)");
- check(!UnifiedReal.E.divide(UnifiedReal.PI).definitelyEquals(
- UnifiedReal.E.divide(UnifiedReal.PI)), "E/PI = E/PI not testable");
- check(new UnifiedReal(32).sqrt().definitelyEquals(
- (new UnifiedReal(2).sqrt().multiply(new UnifiedReal(4)))), "sqrt(32)");
- check(new UnifiedReal(32).ln().divide(UnifiedReal.TWO.ln())
- .definitelyEquals(new UnifiedReal(5)), "ln(32)");
- check(new UnifiedReal(10).sqrt().multiply(UnifiedReal.TEN.sqrt())
- .definitelyEquals(UnifiedReal.TEN), "sqrt(10)^2");
- check(UnifiedReal.ZERO.leadingBinaryZeroes() == Integer.MAX_VALUE, "0.leadingBinaryZeros");
- check(new UnifiedReal(new BoundedRational(7,1024)).leadingBinaryZeroes() >= 8,
- "fract.leadingBinaryZeros");
- UnifiedReal tmp = UnifiedReal.TEN.pow(new UnifiedReal(-1000));
- int tmp2 = tmp.leadingBinaryZeroes();
- check(tmp2 >= 3320 && tmp2 < 4000, "leadingBinaryZeroes(10^-1000)");
- tmp2 = tmp.multiply(UnifiedReal.PI).leadingBinaryZeroes();
- check(tmp2 >= 3319 && tmp2 < 4000, "leadingBinaryZeroes(pix10^-1000)");
- // We check values that include all interesting degree values.
- r = new UnifiedReal(-390);
- int i = 0;
- while (!r.definitelyEquals(new UnifiedReal(390))) {
- check(i++ < 100, "int loop counter arithmetic failed!");
- if (i > 100) {
- break;
- }
- checkUR(r);
- r = r.add(new UnifiedReal(15));
- }
- r = UnifiedReal.PI.multiply(new UnifiedReal(-3));
- final UnifiedReal limit = r.negate();
- final UnifiedReal increment = UnifiedReal.PI.divide(new UnifiedReal(24));
- i = 0;
- while (!r.definitelyEquals(limit)) {
- check(i++ < 200, "transcendental loop counter arithmetic failed!");
- if (i > 100) {
- break;
- }
- checkUR(r);
- r = r.add(increment);
- }
- checkUR(UnifiedReal.HALF);
- checkUR(UnifiedReal.MINUS_HALF);
- checkUR(UnifiedReal.ONE);
- checkUR(UnifiedReal.MINUS_ONE);
- checkUR(new UnifiedReal(1000));
- checkUR(new UnifiedReal(100));
- checkUR(new UnifiedReal(new BoundedRational(4,9)));
- check(new UnifiedReal(new BoundedRational(4,9)).sqrt().definitelyEquals(
- UnifiedReal.TWO.divide(new UnifiedReal(3))), "sqrt(4/9)");
- checkUR(new UnifiedReal(new BoundedRational(4,9)).negate());
- checkUR(new UnifiedReal(new BoundedRational(5,9)));
- checkUR(new UnifiedReal(new BoundedRational(5,10)));
- checkUR(new UnifiedReal(new BoundedRational(5,10)));
- checkUR(new UnifiedReal(new BoundedRational(4,13)));
- checkUR(new UnifiedReal(36));
- checkUR(new UnifiedReal(36).negate());
- }
-
- public void testFunctionsOnSmall() {
- // This checks some of the special cases we should handle semi-symbolically.
- UnifiedReal small = new UnifiedReal(2).pow(new UnifiedReal(-1000));
- UnifiedReal small2 = new UnifiedReal(-1000).exp();
- for (int i = 0; i <= 10; i++) {
- UnifiedReal r = new UnifiedReal(i);
- UnifiedReal sqrt = r.sqrt();
- if (i > 1 && i != 4 && i != 9) {
- check(sqrt.definitelyIrrational() && !sqrt.definitelyRational(), "sqrt !rational");
- } else {
- check(!sqrt.definitelyIrrational() && sqrt.definitelyRational(), "sqrt rational");
- }
- check(sqrt.definitelyAlgebraic() && !sqrt.definitelyTranscendental(), "sqrt algenraic");
- check(sqrt.multiply(sqrt).definitelyEquals(r), "sqrt " + i);
- check(!sqrt.multiply(sqrt).definitelyEquals(r.add(small)), "sqrt small " + i);
- check(!sqrt.multiply(sqrt).definitelyEquals(r.add(small2)), "sqrt small2 " + i);
- if (i > 0) {
- UnifiedReal log = r.ln();
- check(log.exp().definitelyEquals(r), "log " + i);
- if (i > 1) {
- check(log.definitelyTranscendental(), "log transcendental");
- check(!log.definitelyAlgebraic(), "log !algebraic");
- check(!log.definitelyRational(), "log !rational");
- check(log.definitelyIrrational(), "log !rational again");
- } else {
- check(log.definitelyRational(), "log rational");
- }
- check(r.pow(r).ln().definitelyEquals(r.multiply(r.ln())), "ln(r^r)");
- }
- }
- }
-
- public void testURexceptions() {
- try {
- UnifiedReal.MINUS_ONE.ln();
- check(false, "ln(-1)");
- } catch (ArithmeticException ignored) {}
- try {
- UnifiedReal.MINUS_ONE.sqrt();
- check(false, "sqrt(-1)");
- } catch (ArithmeticException ignored) {}
- try {
- new UnifiedReal(-2).asin();
- check(false, "asin(-2)");
- } catch (ArithmeticException ignored) {}
- try {
- new UnifiedReal(-2).acos();
- check(false, "acos(-2)");
- } catch (ArithmeticException ignored) {}
- }
-
-}