From e6762dcec15413e920ccc8883bd64c1b170d3954 Mon Sep 17 00:00:00 2001 From: WddVictor <908704496@qq.com> Date: Fri, 20 Dec 2019 23:21:49 +0800 Subject: [PATCH 1/2] Resolve the bug of C and add a test case --- .../calculator/MainActivityTest.java | 16 ++++++++++++++++ .../calculator/helpers/CalculatorImpl.kt | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/java/com/simplemobiletools/calculator/MainActivityTest.java b/app/src/androidTest/java/com/simplemobiletools/calculator/MainActivityTest.java index c64bd65a..0b52de1a 100644 --- a/app/src/androidTest/java/com/simplemobiletools/calculator/MainActivityTest.java +++ b/app/src/androidTest/java/com/simplemobiletools/calculator/MainActivityTest.java @@ -42,6 +42,22 @@ public class MainActivityTest { checkResult("5"); } + @Test + public void clearComplexTest(){ + press(R.id.btn_1); + press(R.id.btn_plus); + press(R.id.btn_1); + press(R.id.btn_decimal); + press(R.id.btn_5); + press(R.id.btn_5); + press(R.id.btn_clear); + press(R.id.btn_1); + press(R.id.btn_equals); + checkResult("2.51"); + checkFormula("1+1.51"); + } + + @Test public void additionTest() { press(R.id.btn_minus); diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt index 9551c73a..ab8c1601 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -161,7 +161,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) { newValue = newValue.replace("\\.$".toRegex(), "") newValue = formatString(newValue) setValue(newValue) - mBaseValue = Formatter.stringToDouble(newValue) } } From 6a21edba9790d1858dbdea6578474233aba0c7c1 Mon Sep 17 00:00:00 2001 From: WddVictor <908704496@qq.com> Date: Fri, 20 Dec 2019 23:47:47 +0800 Subject: [PATCH 2/2] fix the bug of % and pass the test case percentageTest --- .../calculator/helpers/CalculatorImpl.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt index ab8c1601..e28c8d2a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -13,7 +13,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) { private var mIsFirstOperation = false private var mResetValue = false - private var mWasPercentLast = false private var mBaseValue = 0.0 private var mSecondValue = 0.0 @@ -62,9 +61,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) { setFormula(first + sign) } else if (!sign.isEmpty()) { var formula = first + sign + second - if (mWasPercentLast) { - formula += "%" - } setFormula(formula) } } @@ -111,9 +107,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) { private fun calculateResult() { updateFormula() - if (mWasPercentLast) { - mSecondValue *= mBaseValue / 100 - } val operation = OperationFactory.forId(mLastOperation!!, mBaseValue, mSecondValue) if (operation != null) { @@ -124,7 +117,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) { } fun handleOperation(operation: String) { - mWasPercentLast = operation == PERCENT if (lastKey == DIGIT && operation != ROOT && operation != FACTORIAL) { handleResult() }