updating Unit tests style
This commit is contained in:
parent
9257edd92e
commit
4d466a696b
|
@ -15,11 +15,7 @@ import org.robolectric.annotation.Config
|
||||||
class MainActivityTest {
|
class MainActivityTest {
|
||||||
private lateinit var activity: MainActivity
|
private lateinit var activity: MainActivity
|
||||||
|
|
||||||
private val displayedNumber: String?
|
private fun getDisplayedNumber() = activity.calc.displayedNumber
|
||||||
get() = activity.calc.displayedNumber
|
|
||||||
|
|
||||||
private val displayedFormula: String?
|
|
||||||
get() = activity.calc.displayedFormula
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
@ -29,14 +25,14 @@ class MainActivityTest {
|
||||||
@Test
|
@Test
|
||||||
fun addSimpleDigit() {
|
fun addSimpleDigit() {
|
||||||
activity.calc.addDigit(2)
|
activity.calc.addDigit(2)
|
||||||
assertEquals("2", displayedNumber)
|
assertEquals("2", getDisplayedNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun removeLeadingZero() {
|
fun removeLeadingZero() {
|
||||||
activity.calc.addDigit(0)
|
activity.calc.addDigit(0)
|
||||||
activity.calc.addDigit(5)
|
activity.calc.addDigit(5)
|
||||||
assertEquals("5", displayedNumber)
|
assertEquals("5", getDisplayedNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,7 +88,7 @@ class MainActivityTest {
|
||||||
fun rootTest() {
|
fun rootTest() {
|
||||||
setDouble(16.0)
|
setDouble(16.0)
|
||||||
handleOperation(ROOT)
|
handleOperation(ROOT)
|
||||||
assertEquals("4", displayedNumber)
|
assertEquals("4", getDisplayedNumber())
|
||||||
checkFormula("√16")
|
checkFormula("√16")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,16 +96,16 @@ class MainActivityTest {
|
||||||
fun clearBtnSimpleTest() {
|
fun clearBtnSimpleTest() {
|
||||||
setDouble(156.0)
|
setDouble(156.0)
|
||||||
activity.calc.handleClear()
|
activity.calc.handleClear()
|
||||||
assertEquals("15", displayedNumber)
|
assertEquals("15", getDisplayedNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun clearBtnComplexTest() {
|
fun clearBtnComplexTest() {
|
||||||
setDouble(-26.0)
|
setDouble(-26.0)
|
||||||
activity.calc.handleClear()
|
activity.calc.handleClear()
|
||||||
assertEquals("-2", displayedNumber)
|
assertEquals("-2", getDisplayedNumber())
|
||||||
activity.calc.handleClear()
|
activity.calc.handleClear()
|
||||||
assertEquals("0", displayedNumber)
|
assertEquals("0", getDisplayedNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -119,7 +115,7 @@ class MainActivityTest {
|
||||||
handleOperation(PLUS)
|
handleOperation(PLUS)
|
||||||
setDouble(3.0)
|
setDouble(3.0)
|
||||||
activity.calc.handleResult()
|
activity.calc.handleResult()
|
||||||
assertEquals("3", displayedNumber)
|
assertEquals("3", getDisplayedNumber())
|
||||||
checkFormula("")
|
checkFormula("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,40 +125,40 @@ class MainActivityTest {
|
||||||
handleOperation(PLUS)
|
handleOperation(PLUS)
|
||||||
setDouble(21.0)
|
setDouble(21.0)
|
||||||
handleOperation(MINUS)
|
handleOperation(MINUS)
|
||||||
assertEquals("8.8", displayedNumber)
|
assertEquals("8.8", getDisplayedNumber())
|
||||||
checkFormula("-12.2+21")
|
checkFormula("-12.2+21")
|
||||||
|
|
||||||
setDouble(1.6)
|
setDouble(1.6)
|
||||||
activity.calc.handleEquals()
|
activity.calc.handleEquals()
|
||||||
assertEquals("7.2", displayedNumber)
|
assertEquals("7.2", getDisplayedNumber())
|
||||||
checkFormula("8.8-1.6")
|
checkFormula("8.8-1.6")
|
||||||
activity.calc.handleEquals()
|
activity.calc.handleEquals()
|
||||||
assertEquals("5.6", displayedNumber)
|
assertEquals("5.6", getDisplayedNumber())
|
||||||
checkFormula("7.2-1.6")
|
checkFormula("7.2-1.6")
|
||||||
|
|
||||||
handleOperation(MULTIPLY)
|
handleOperation(MULTIPLY)
|
||||||
setDouble(5.0)
|
setDouble(5.0)
|
||||||
handleOperation(DIVIDE)
|
handleOperation(DIVIDE)
|
||||||
assertEquals("28", displayedNumber)
|
assertEquals("28", getDisplayedNumber())
|
||||||
checkFormula("5.6*5")
|
checkFormula("5.6*5")
|
||||||
|
|
||||||
setDouble(4.0)
|
setDouble(4.0)
|
||||||
handleOperation(MODULO)
|
handleOperation(MODULO)
|
||||||
assertEquals("7", displayedNumber)
|
assertEquals("7", getDisplayedNumber())
|
||||||
checkFormula("28/4")
|
checkFormula("28/4")
|
||||||
|
|
||||||
setDouble(5.0)
|
setDouble(5.0)
|
||||||
handleOperation(POWER)
|
handleOperation(POWER)
|
||||||
assertEquals("2", displayedNumber)
|
assertEquals("2", getDisplayedNumber())
|
||||||
checkFormula("7%5")
|
checkFormula("7%5")
|
||||||
|
|
||||||
setDouble(8.0)
|
setDouble(8.0)
|
||||||
handleOperation(ROOT)
|
handleOperation(ROOT)
|
||||||
assertEquals("16", displayedNumber)
|
assertEquals("16", getDisplayedNumber())
|
||||||
checkFormula("√256")
|
checkFormula("√256")
|
||||||
|
|
||||||
activity.calc.handleClear()
|
activity.calc.handleClear()
|
||||||
assertEquals("1", displayedNumber)
|
assertEquals("1", getDisplayedNumber())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setDouble(d: Double) {
|
private fun setDouble(d: Double) {
|
||||||
|
@ -174,7 +170,7 @@ class MainActivityTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkFormula(desired: String) {
|
private fun checkFormula(desired: String) {
|
||||||
assertEquals(desired, displayedFormula)
|
assertEquals(desired, activity.calc.displayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calcResult(baseValue: Double, operation: String, secondValue: Double): String? {
|
private fun calcResult(baseValue: Double, operation: String, secondValue: Double): String? {
|
||||||
|
@ -182,6 +178,6 @@ class MainActivityTest {
|
||||||
handleOperation(operation)
|
handleOperation(operation)
|
||||||
setDouble(secondValue)
|
setDouble(secondValue)
|
||||||
activity.calc.handleResult()
|
activity.calc.handleResult()
|
||||||
return displayedNumber
|
return getDisplayedNumber()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue