Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75ca21c6 authored by Hans Boehm's avatar Hans Boehm
Browse files

Add tests, fix BoundedRational bugs

Add back some basic test infrastructure from the KitKat calculator,
updated to make it work with the current code base and asynchronous
expression evaluation.

Add BoundedRational tests, designed to check that we get all the
corner cases, particularly for degree-based trig functions, right.

Fix a couple of BoundedRational typos that caused these tests to fail.

Change-Id: I81d8f3d9bde6aa6c20f9958eabd62979babeff5b
parent 682ff5e8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ LOCAL_SDK_VERSION := current

LOCAL_PACKAGE_NAME := ExactCalculator

LOCAL_PROGUARD_FLAG_FILES := proguard.flags

LOCAL_AAPT_FLAGS := --rename-manifest-package com.android.exactcalculator

include $(BUILD_PACKAGE)

include $(call all-makefiles-under,$(LOCAL_PATH))

proguard.flags

0 → 100644
+4 −0
Original line number Diff line number Diff line
# Some small BoundedRational methods like equals() are not used by the
# calculator, but crucial for testing.

-keepclassmembers class com.android.calculator2.BoundedRational { *; }
+7 −3
Original line number Diff line number Diff line
@@ -62,9 +62,13 @@ public class BoundedRational {
    }

    // Debug or log messages only, not pretty.
    public String toString() {
        return mNum.toString() + "/" + mDen.toString();
    }

    public static String toString(BoundedRational r) {
        if (r == null) return "not a small rational";
        return r.mNum.toString() + "/" + r.mDen.toString();
        return r.toString();
    }

    // Primarily for debugging; clearly not exact
@@ -113,7 +117,7 @@ public class BoundedRational {
    }

    public int signum() {
        return mDen.signum() * mDen.signum();
        return mNum.signum() * mDen.signum();
    }

    public boolean equals(BoundedRational r) {
@@ -184,7 +188,7 @@ public class BoundedRational {
        if (!num_sqrt.multiply(num_sqrt).equals(r.mNum)) return null;
        final BigInteger den_sqrt = BigInteger.valueOf(Math.round(Math.sqrt(
                                                   r.mDen.doubleValue())));
        if (!num_sqrt.multiply(den_sqrt).equals(r.mDen)) return null;
        if (!den_sqrt.multiply(den_sqrt).equals(r.mDen)) return null;
        return new BoundedRational(num_sqrt, den_sqrt);
    }

tests/Android.mk

0 → 100644
+20 −0
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SDK_VERSION := current

# We only want this apk build for tests.
LOCAL_MODULE_TAGS := tests

# LOCAL_JAVA_LIBRARIES := android.test.runner

# Include all test java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_PACKAGE_NAME := ExactCalculatorTests

LOCAL_INSTRUMENTATION_FOR := ExactCalculator

LOCAL_AAPT_FLAGS := --rename-manifest-package com.android.exactcalculator.tests

include $(BUILD_PACKAGE)
+33 −0
Original line number Diff line number Diff line
<?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.exactcalculator"
        android:label="BoundedRational and Calculator Functional Test">
    </instrumentation>

    <application>
        <uses-library android:name="android.test.runner" />
    </application>

</manifest>
Loading