Last active
July 7, 2024 13:53
-
-
Save birojow/d75b9760f1bfbd418ca4f2c7c9f20e7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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