Skip to content

Instantly share code, notes, and snippets.

@birojow
Last active July 7, 2024 13:53
Show Gist options
  • Select an option

  • Save birojow/d75b9760f1bfbd418ca4f2c7c9f20e7d to your computer and use it in GitHub Desktop.

Select an option

Save birojow/d75b9760f1bfbd418ca4f2c7c9f20e7d to your computer and use it in GitHub Desktop.
@Test
fun shouldCalculateExpressionsCorrectly() {
// arrange
enterFormula("((515 + 87 x 311) - 302) ÷ 27")
// act
performCalculation()
// assert
assertResultIs("1010.0")
}
private fun enterFormula(formula: String) {
formula.forEach { character ->
if (!character.isWhitespace()) {
val buttonLabel = when (character) {
'(', ')' -> "()"
else -> character.toString()
}
composeRule
.onNodeWithText(buttonLabel)
.performClick()
}
}
}
private fun performCalculation() {
composeRule
.onNodeWithText("=")
.performClick()
}
private fun assertResultIs(result: String) {
composeRule
.onNodeWithText(result)
.assertIsDisplayed()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment