mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
Add brackets to formatter
This commit is contained in:
parent
0566387d81
commit
b46d799382
@ -24,6 +24,8 @@ import android.net.Uri
|
||||
import com.sadellie.unitto.data.KEY_COMMA
|
||||
import com.sadellie.unitto.data.KEY_DOT
|
||||
import com.sadellie.unitto.data.KEY_E
|
||||
import com.sadellie.unitto.data.KEY_LEFT_BRACKET
|
||||
import com.sadellie.unitto.data.KEY_RIGHT_BRACKET
|
||||
import com.sadellie.unitto.data.OPERATORS
|
||||
import com.sadellie.unitto.data.preferences.OutputFormat
|
||||
import com.sadellie.unitto.data.preferences.Separator
|
||||
@ -83,7 +85,7 @@ object Formatter {
|
||||
// We may receive expressions
|
||||
// Find all numbers in that expression
|
||||
val allNumbers: List<String> = input.split(
|
||||
*OPERATORS.toTypedArray()
|
||||
*OPERATORS.toTypedArray(), KEY_LEFT_BRACKET, KEY_RIGHT_BRACKET
|
||||
)
|
||||
|
||||
allNumbers.forEach {
|
||||
|
@ -31,6 +31,7 @@ private const val INCOMPLETE_VALUE = "123456."
|
||||
private const val NO_FRACTIONAL_VALUE = "123456"
|
||||
private const val INCOMPLETE_EXPR = "50+123456÷8×0.8–12+"
|
||||
private const val COMPLETE_EXPR = "50+123456÷8×0.8–12+0-√9*4^9+2×(9+8×7)"
|
||||
private const val SOME_BRACKETS = "(((((((("
|
||||
|
||||
class FormatterTest {
|
||||
|
||||
@ -45,6 +46,7 @@ class FormatterTest {
|
||||
assertEquals("123 456", formatter.format(NO_FRACTIONAL_VALUE))
|
||||
assertEquals("50+123 456÷8×0.8–12+", formatter.format(INCOMPLETE_EXPR))
|
||||
assertEquals("50+123 456÷8×0.8–12+0-√9*4^9+2×(9+8×7)", formatter.format(COMPLETE_EXPR))
|
||||
assertEquals("((((((((", formatter.format(SOME_BRACKETS))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -58,6 +60,7 @@ class FormatterTest {
|
||||
assertEquals("123,456", formatter.format(NO_FRACTIONAL_VALUE))
|
||||
assertEquals("50+123,456÷8×0.8–12+", formatter.format(INCOMPLETE_EXPR))
|
||||
assertEquals("50+123,456÷8×0.8–12+0-√9*4^9+2×(9+8×7)", formatter.format(COMPLETE_EXPR))
|
||||
assertEquals("((((((((", formatter.format(SOME_BRACKETS))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,6 +74,7 @@ class FormatterTest {
|
||||
assertEquals("123.456", formatter.format(NO_FRACTIONAL_VALUE))
|
||||
assertEquals("50+123.456÷8×0,8–12+", formatter.format(INCOMPLETE_EXPR))
|
||||
assertEquals("50+123.456÷8×0,8–12+0-√9*4^9+2×(9+8×7)", formatter.format(COMPLETE_EXPR))
|
||||
assertEquals("((((((((", formatter.format(SOME_BRACKETS))
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user