mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
removing the tests
This commit is contained in:
17
README.md
17
README.md
@ -20,20 +20,3 @@ This app is just one piece of a bigger series of apps. You can find the rest of
|
|||||||
<img alt="App image" src="fastlane/metadata/android/en-US/images/phoneScreenshots/app_3.jpg" width="30%">
|
<img alt="App image" src="fastlane/metadata/android/en-US/images/phoneScreenshots/app_3.jpg" width="30%">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br>
|
|
||||||
It contains a couple UI and unit tests, they can be ran with the following instructions.
|
|
||||||
|
|
||||||
<h3>Running Espresso UI tests</h3>
|
|
||||||
<p>1. Run -> Edit Configurations</p>
|
|
||||||
<p>2. Create a new "Android Instrumentation Tests" configuration, give it a name (i.e. "MainActivityEspressoTest")</p>
|
|
||||||
<p>3. Choose the "app" module</p>
|
|
||||||
<p>4. OK</p>
|
|
||||||
<p>5. Make sure MainActivityEspressoTest is selected near the Run button</p>
|
|
||||||
<p>6. Run</p>
|
|
||||||
|
|
||||||
<h3>Running Robolectric tests</h3>
|
|
||||||
<p>1. At the Project tab right click the folder containing the tests (i.e. "calculator.simplemobiletools.com.simple_calculator (test)")</p>
|
|
||||||
<p>2. select Run 'Tests in 'calculator.simplemob...' to run all the tests</p>
|
|
||||||
<p>3. if you are on Linux or Mac, go to Run -> Edit Configurations, select the new JUnit configuration and change the "Working Directory" item to "$MODULE_DIR$" (without quotes)</p>
|
|
||||||
<p>4. OK</p>
|
|
||||||
<p>5. Run</p>
|
|
||||||
|
@ -18,8 +18,6 @@ android {
|
|||||||
versionCode 36
|
versionCode 36
|
||||||
versionName "5.3.0"
|
versionName "5.3.0"
|
||||||
setProperty("archivesBaseName", "calculator")
|
setProperty("archivesBaseName", "calculator")
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
@ -60,12 +58,4 @@ dependencies {
|
|||||||
implementation 'com.simplemobiletools:commons:5.31.25'
|
implementation 'com.simplemobiletools:commons:5.31.25'
|
||||||
implementation 'me.grantland:autofittextview:0.2.1'
|
implementation 'me.grantland:autofittextview:0.2.1'
|
||||||
implementation 'net.objecthunter:exp4j:0.4.8'
|
implementation 'net.objecthunter:exp4j:0.4.8'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
|
||||||
testImplementation 'org.robolectric:robolectric:4.2'
|
|
||||||
|
|
||||||
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
|
|
||||||
androidTestImplementation 'androidx.test:runner:1.3.0-rc03'
|
|
||||||
androidTestImplementation 'androidx.test:rules:1.3.0-rc03'
|
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-rc03'
|
|
||||||
}
|
}
|
||||||
|
@ -1,247 +0,0 @@
|
|||||||
package com.simplemobiletools.calculator;
|
|
||||||
|
|
||||||
import androidx.test.rule.ActivityTestRule;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import com.simplemobiletools.calculator.activities.MainActivity;
|
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import static androidx.test.espresso.Espresso.onView;
|
|
||||||
import static androidx.test.espresso.action.ViewActions.click;
|
|
||||||
import static androidx.test.espresso.action.ViewActions.longClick;
|
|
||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
|
||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class MainActivityTest {
|
|
||||||
@Rule public final ActivityTestRule<MainActivity> activity = new ActivityTestRule<>(MainActivity.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addDigits() {
|
|
||||||
press(R.id.btn_1);
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_3);
|
|
||||||
press(R.id.btn_4);
|
|
||||||
press(R.id.btn_5);
|
|
||||||
press(R.id.btn_6);
|
|
||||||
press(R.id.btn_7);
|
|
||||||
press(R.id.btn_8);
|
|
||||||
press(R.id.btn_9);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
checkResult("1,234,567,890");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void removeLeadingZero() {
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_5);
|
|
||||||
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_0);
|
|
||||||
press(R.id.btn_minus);
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_decimal);
|
|
||||||
press(R.id.btn_5);
|
|
||||||
press(R.id.btn_plus);
|
|
||||||
press(R.id.btn_6);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("3.5");
|
|
||||||
checkFormula("-2.5+6");
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("9.5");
|
|
||||||
checkFormula("3.5+6");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void subtractionTest() {
|
|
||||||
press(R.id.btn_7);
|
|
||||||
press(R.id.btn_decimal);
|
|
||||||
press(R.id.btn_8);
|
|
||||||
press(R.id.btn_minus);
|
|
||||||
press(R.id.btn_3);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("4.8");
|
|
||||||
checkFormula("7.8-3");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void multiplyTest() {
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_multiply);
|
|
||||||
press(R.id.btn_4);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("8");
|
|
||||||
checkFormula("2*4");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void divisionTest() {
|
|
||||||
press(R.id.btn_1);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_divide);
|
|
||||||
press(R.id.btn_4);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("2.5");
|
|
||||||
checkFormula("10/4");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void divisionByZeroTest() {
|
|
||||||
press(R.id.btn_8);
|
|
||||||
press(R.id.btn_divide);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("0");
|
|
||||||
checkFormula("8/0");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void percentTest() {
|
|
||||||
press(R.id.btn_1);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_percent);
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("2");
|
|
||||||
checkFormula("10%20");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void percentTestInsideOtherOperation() {
|
|
||||||
press(R.id.btn_8);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_minus);
|
|
||||||
press(R.id.btn_1);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_percent);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("72");
|
|
||||||
checkFormula("80-10%");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void powerTest() {
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_power);
|
|
||||||
press(R.id.btn_3);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("8");
|
|
||||||
checkFormula("2^3");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void rootTest() {
|
|
||||||
press(R.id.btn_9);
|
|
||||||
press(R.id.btn_root);
|
|
||||||
checkResult("3");
|
|
||||||
checkFormula("√9");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void clearTest() {
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_5);
|
|
||||||
press(R.id.btn_decimal);
|
|
||||||
press(R.id.btn_7);
|
|
||||||
press(R.id.btn_clear);
|
|
||||||
checkResult("25");
|
|
||||||
press(R.id.btn_clear);
|
|
||||||
checkResult("2");
|
|
||||||
press(R.id.btn_clear);
|
|
||||||
checkResult("0");
|
|
||||||
press(R.id.btn_clear);
|
|
||||||
checkResult("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void clearLongTest() {
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_plus);
|
|
||||||
press(R.id.btn_5);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
longPress((R.id.btn_clear));
|
|
||||||
press(R.id.btn_plus);
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("2");
|
|
||||||
checkFormula("0+2");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void complexTest() {
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_plus);
|
|
||||||
press(R.id.btn_5);
|
|
||||||
press(R.id.btn_minus);
|
|
||||||
checkResult("7");
|
|
||||||
checkFormula("2+5");
|
|
||||||
|
|
||||||
press(R.id.btn_3);
|
|
||||||
press(R.id.btn_multiply);
|
|
||||||
checkResult("4");
|
|
||||||
checkFormula("7-3");
|
|
||||||
|
|
||||||
press(R.id.btn_1);
|
|
||||||
press(R.id.btn_0);
|
|
||||||
press(R.id.btn_divide);
|
|
||||||
checkResult("40");
|
|
||||||
checkFormula("4*10");
|
|
||||||
|
|
||||||
press(R.id.btn_5);
|
|
||||||
press(R.id.btn_power);
|
|
||||||
checkResult("8");
|
|
||||||
checkFormula("40/5");
|
|
||||||
|
|
||||||
press(R.id.btn_2);
|
|
||||||
press(R.id.btn_equals);
|
|
||||||
checkResult("64");
|
|
||||||
checkFormula("8^2");
|
|
||||||
|
|
||||||
press(R.id.btn_root);
|
|
||||||
checkResult("8");
|
|
||||||
checkFormula("√64");
|
|
||||||
|
|
||||||
press(R.id.btn_clear);
|
|
||||||
checkResult("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void press(int id) {
|
|
||||||
onView(withId(id)).perform(click());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void longPress(int id) {
|
|
||||||
onView(withId(id)).perform(longClick());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkResult(String desired) {
|
|
||||||
onView(withId(R.id.result)).check(matches(withText(desired)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkFormula(String desired) {
|
|
||||||
onView(withId(R.id.formula)).check(matches(withText(desired)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
package com.simplemobiletools.calculator
|
|
||||||
|
|
||||||
import androidx.test.espresso.Espresso
|
|
||||||
import androidx.test.espresso.action.ViewActions
|
|
||||||
import androidx.test.espresso.assertion.ViewAssertions
|
|
||||||
import androidx.test.espresso.matcher.ViewMatchers
|
|
||||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
|
||||||
import androidx.test.rule.ActivityTestRule
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
||||||
import com.simplemobiletools.calculator.activities.MainActivity
|
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
|
||||||
class PercentTests {
|
|
||||||
@Rule
|
|
||||||
@JvmField
|
|
||||||
var activity = ActivityTestRule(MainActivity::class.java)
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun percentTest_asTheFirstOperation() {
|
|
||||||
press(R.id.btn_1)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_percent)
|
|
||||||
press(R.id.btn_2)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_equals)
|
|
||||||
checkResult("2")
|
|
||||||
checkFormula("10%20")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun percentTestInsideOtherOperation1() {
|
|
||||||
press(R.id.btn_8)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_minus)
|
|
||||||
press(R.id.btn_1)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_percent)
|
|
||||||
press(R.id.btn_equals)
|
|
||||||
checkResult("72")
|
|
||||||
checkFormula("80-10%")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun percentTestInsideOtherOperation2() {
|
|
||||||
press(R.id.btn_5)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_minus)
|
|
||||||
press(R.id.btn_2)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_percent)
|
|
||||||
press(R.id.btn_equals)
|
|
||||||
checkResult("40")
|
|
||||||
checkFormula("50-20%")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun percentTestInsideComplexOperation() {
|
|
||||||
press(R.id.btn_8)
|
|
||||||
press(R.id.btn_multiply)
|
|
||||||
press(R.id.btn_1)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_equals)
|
|
||||||
checkResult("80")
|
|
||||||
press(R.id.btn_minus)
|
|
||||||
press(R.id.btn_2)
|
|
||||||
press(R.id.btn_0)
|
|
||||||
press(R.id.btn_percent)
|
|
||||||
press(R.id.btn_equals)
|
|
||||||
checkResult("64")
|
|
||||||
checkFormula("80-20%")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun press(id: Int) {
|
|
||||||
Espresso.onView(withId(id)).perform(ViewActions.click())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun longPress(id: Int) {
|
|
||||||
Espresso.onView(withId(id)).perform(ViewActions.longClick())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkResult(desired: String) {
|
|
||||||
Espresso.onView(withId(R.id.result)).check(ViewAssertions.matches(ViewMatchers.withText(desired)))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkFormula(desired: String) {
|
|
||||||
Espresso.onView(withId(R.id.formula)).check(ViewAssertions.matches(ViewMatchers.withText(desired)))
|
|
||||||
}
|
|
||||||
}
|
|
@ -155,12 +155,6 @@ class MainActivity : SimpleActivity(), Calculator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// used only by Robolectric
|
|
||||||
override fun setValueDouble(d: Double) {
|
|
||||||
calc.setValue(Formatter.doubleToString(d))
|
|
||||||
calc.lastKey = DIGIT
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setFormula(value: String, context: Context) {
|
override fun setFormula(value: String, context: Context) {
|
||||||
formula.text = value
|
formula.text = value
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,5 @@ import android.content.Context
|
|||||||
interface Calculator {
|
interface Calculator {
|
||||||
fun setValue(value: String, context: Context)
|
fun setValue(value: String, context: Context)
|
||||||
|
|
||||||
fun setValueDouble(d: Double)
|
|
||||||
|
|
||||||
fun setFormula(value: String, context: Context)
|
fun setFormula(value: String, context: Context)
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import com.simplemobiletools.commons.extensions.toast
|
|||||||
import net.objecthunter.exp4j.ExpressionBuilder
|
import net.objecthunter.exp4j.ExpressionBuilder
|
||||||
|
|
||||||
class CalculatorImpl(calculator: Calculator, val context: Context) {
|
class CalculatorImpl(calculator: Calculator, val context: Context) {
|
||||||
var displayedNumber: String? = null
|
private var displayedNumber: String? = null
|
||||||
var lastKey: String? = null
|
private var lastKey: String? = null
|
||||||
private var inputDisplayedFormula = "0"
|
private var inputDisplayedFormula = "0"
|
||||||
private var callback: Calculator? = calculator
|
private var callback: Calculator? = calculator
|
||||||
|
|
||||||
|
@ -123,9 +123,6 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setValueDouble(d: Double) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setFormula(value: String, context: Context) {
|
override fun setFormula(value: String, context: Context) {
|
||||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||||
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||||
|
@ -1,183 +0,0 @@
|
|||||||
package com.simplemobiletools.calculator
|
|
||||||
|
|
||||||
import com.simplemobiletools.calculator.activities.MainActivity
|
|
||||||
import com.simplemobiletools.calculator.helpers.*
|
|
||||||
import com.simplemobiletools.calculator.BuildConfig
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.robolectric.Robolectric
|
|
||||||
import org.robolectric.RobolectricTestRunner
|
|
||||||
import org.robolectric.annotation.Config
|
|
||||||
import java.math.BigDecimal
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
|
||||||
class MainActivityTest {
|
|
||||||
private lateinit var activity: MainActivity
|
|
||||||
|
|
||||||
private fun getDisplayedNumber() = activity.calc.displayedNumber
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setUp() {
|
|
||||||
activity = Robolectric.setupActivity(MainActivity::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun addSimpleDigit() {
|
|
||||||
activity.calc.addDigit(2)
|
|
||||||
assertEquals("2", getDisplayedNumber())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun removeLeadingZero() {
|
|
||||||
activity.calc.addDigit(0)
|
|
||||||
activity.calc.addDigit(5)
|
|
||||||
assertEquals("5", getDisplayedNumber())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun additionTest() {
|
|
||||||
val res = calcResult(BigDecimal.valueOf(-1.2), PLUS, BigDecimal.valueOf(3.4))
|
|
||||||
assertEquals("2.2", res)
|
|
||||||
checkFormula("-1.2+3.4")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun subtractionTest() {
|
|
||||||
val res = calcResult(BigDecimal.valueOf(7.8), MINUS, BigDecimal.valueOf(2.5))
|
|
||||||
assertEquals("5.3", res)
|
|
||||||
checkFormula("7.8-2.5")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun multiplyTest() {
|
|
||||||
val res = calcResult(BigDecimal.valueOf(-3.2), MULTIPLY, BigDecimal.valueOf(6.6))
|
|
||||||
assertEquals("-21.12", res)
|
|
||||||
checkFormula("-3.2*6.6")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun divisionTest() {
|
|
||||||
val res = calcResult(BigDecimal.valueOf(18.25), DIVIDE, BigDecimal.valueOf(5.0))
|
|
||||||
assertEquals("3.65", res)
|
|
||||||
checkFormula("18.25/5")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun divisionByZero_returnsZero() {
|
|
||||||
val res = calcResult(BigDecimal.valueOf(6.0), DIVIDE, BigDecimal.valueOf(0.0))
|
|
||||||
assertEquals("0", res)
|
|
||||||
checkFormula("6/0")
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @Test
|
|
||||||
fun moduloTest() {
|
|
||||||
val res = calcResult(6.5, MODULO, 3.0)
|
|
||||||
assertEquals("0.5", res)
|
|
||||||
checkFormula("6.5%3")
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun powerTest() {
|
|
||||||
val res = calcResult(BigDecimal.valueOf(3.0), POWER, BigDecimal.valueOf(6.0))
|
|
||||||
assertEquals("729", res)
|
|
||||||
checkFormula("3^6")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun rootTest() {
|
|
||||||
setBigDecimal(BigDecimal(16.0))
|
|
||||||
handleOperation(ROOT)
|
|
||||||
assertEquals("4", getDisplayedNumber())
|
|
||||||
checkFormula("√16")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun clearBtnSimpleTest() {
|
|
||||||
setBigDecimal(BigDecimal(156.0))
|
|
||||||
activity.calc.handleClear()
|
|
||||||
assertEquals("15", getDisplayedNumber())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun clearBtnComplexTest() {
|
|
||||||
setBigDecimal(BigDecimal(-26.0))
|
|
||||||
activity.calc.handleClear()
|
|
||||||
assertEquals("-2", getDisplayedNumber())
|
|
||||||
activity.calc.handleClear()
|
|
||||||
assertEquals("0", getDisplayedNumber())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun clearBtnLongClick_resetsEverything() {
|
|
||||||
calcResult(BigDecimal.valueOf(-1.2), PLUS, BigDecimal.valueOf(3.4))
|
|
||||||
activity.calc.handleReset()
|
|
||||||
handleOperation(PLUS)
|
|
||||||
setBigDecimal(BigDecimal.valueOf(3.0))
|
|
||||||
activity.calc.handleResult()
|
|
||||||
assertEquals("3", getDisplayedNumber())
|
|
||||||
checkFormula("")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun complexTest() {
|
|
||||||
setBigDecimal(BigDecimal.valueOf(-12.2))
|
|
||||||
handleOperation(PLUS)
|
|
||||||
setBigDecimal(BigDecimal(21.0))
|
|
||||||
handleOperation(MINUS)
|
|
||||||
assertEquals("8.8", getDisplayedNumber())
|
|
||||||
checkFormula("-12.2+21")
|
|
||||||
|
|
||||||
setBigDecimal(BigDecimal(1.6))
|
|
||||||
activity.calc.handleEquals()
|
|
||||||
assertEquals("7.2", getDisplayedNumber())
|
|
||||||
checkFormula("8.8-1.6")
|
|
||||||
activity.calc.handleEquals()
|
|
||||||
assertEquals("5.6", getDisplayedNumber())
|
|
||||||
checkFormula("7.2-1.6")
|
|
||||||
|
|
||||||
handleOperation(MULTIPLY)
|
|
||||||
setBigDecimal(BigDecimal(5.0))
|
|
||||||
handleOperation(DIVIDE)
|
|
||||||
assertEquals("28", getDisplayedNumber())
|
|
||||||
checkFormula("5.6*5")
|
|
||||||
|
|
||||||
setBigDecimal(BigDecimal(4.0))
|
|
||||||
handleOperation(DIVIDE)
|
|
||||||
assertEquals("7", getDisplayedNumber())
|
|
||||||
checkFormula("28/4")
|
|
||||||
|
|
||||||
setBigDecimal(BigDecimal(5.0))
|
|
||||||
handleOperation(POWER)
|
|
||||||
assertEquals("2", getDisplayedNumber())
|
|
||||||
checkFormula("7%5")
|
|
||||||
|
|
||||||
setBigDecimal(BigDecimal(8.0))
|
|
||||||
handleOperation(ROOT)
|
|
||||||
assertEquals("16", getDisplayedNumber())
|
|
||||||
checkFormula("√256")
|
|
||||||
|
|
||||||
activity.calc.handleClear()
|
|
||||||
assertEquals("1", getDisplayedNumber())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setBigDecimal(d: BigDecimal) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleOperation(operation: String) {
|
|
||||||
activity.calc.handleOperation(operation)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkFormula(desired: String) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun calcResult(baseValue: BigDecimal, operation: String, secondValue: BigDecimal): String? {
|
|
||||||
setBigDecimal(baseValue)
|
|
||||||
handleOperation(operation)
|
|
||||||
setBigDecimal(secondValue)
|
|
||||||
activity.calc.handleResult()
|
|
||||||
return getDisplayedNumber()
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user