[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] 09/15: [taler-android] Improved and refactored tes
From: |
gnunet |
Subject: |
[taler-taler-android] 09/15: [taler-android] Improved and refactored testToString test |
Date: |
Wed, 27 Mar 2024 18:27:12 +0100 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository taler-android.
commit 5b6ba02e4e3026d08807431b144c5b3c1125266c
Author: Iván Ávalos <avalos@disroot.org>
AuthorDate: Thu Mar 14 09:52:47 2024 -0600
[taler-android] Improved and refactored testToString test
(cherry picked from commit b0dccee42d631e078a45f1ed8fd45019801ba4e7)
---
.../src/test/java/net/taler/common/AmountTest.kt | 143 ++++++++++++++++-----
1 file changed, 113 insertions(+), 30 deletions(-)
diff --git a/taler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt
b/taler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt
index e7fb273..8a92764 100644
--- a/taler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt
+++ b/taler-kotlin-android/src/test/java/net/taler/common/AmountTest.kt
@@ -61,48 +61,131 @@ class AmountTest {
@Test
fun testToString() {
- val symbols = DecimalFormatSymbols.getInstance()
- symbols.decimalSeparator = '.'
- symbols.groupingSeparator = ','
- symbols.monetaryDecimalSeparator = '.'
- if (Build.VERSION.SDK_INT >= 34) {
- symbols.monetaryGroupingSeparator = ','
- }
+ amountToString(
+ amount = Amount.fromString("KUDOS", "13.71"),
+ spec = CurrencySpecification(
+ name = "Test (Taler Demostrator)",
+ numFractionalInputDigits = 2,
+ numFractionalNormalDigits = 2,
+ numFractionalTrailingZeroDigits = 2,
+ altUnitNames = mapOf(0 to "ク"),
+ ),
+ rawStr = "13.71",
+ fraction = 71000000,
+ specAmount = "13.71",
+ noSpecAmount = "13.71",
+ currency = "KUDOS",
+ symbol = "ク",
+ )
+
+ amountToString(
+ amount = Amount.fromString("TESTKUDOS", "23.42"),
+ spec = CurrencySpecification(
+ name = "Test (Taler Unstable Demostrator)",
+ numFractionalInputDigits = 0,
+ numFractionalNormalDigits = 0,
+ numFractionalTrailingZeroDigits = 0,
+ altUnitNames = mapOf(0 to "テ"),
+ ),
+ rawStr = "23.42",
+ fraction = 42000000,
+ specAmount = "23",
+ noSpecAmount = "23.42",
+ currency = "TESTKUDOS",
+ symbol = "テ",
+ )
- val spec = CurrencySpecification(
- name = "Bitcoin",
- numFractionalInputDigits = 8,
- numFractionalNormalDigits = 8,
- numFractionalTrailingZeroDigits = 0,
- altUnitNames = mapOf(
- 0 to "₿",
- // TODO: uncomment when units get implemented
- // and then write tests for units, please
+ amountToString(
+ amount = Amount.fromString("BITCOINBTC", "0.00000001"),
+ spec = CurrencySpecification(
+ name = "Bitcoin",
+ numFractionalInputDigits = 8,
+ numFractionalNormalDigits = 8,
+ numFractionalTrailingZeroDigits = 0,
+ altUnitNames = mapOf(
+ 0 to "₿",
+ // TODO: uncomment when units get implemented
+ // and then write tests for units, please
// -1 to "d₿",
// -2 to "c₿",
// -3 to "m₿",
// -6 to "µ₿",
// -8 to "sat",
+ ),
),
+ rawStr = "0.00000001",
+ fraction = 1,
+ specAmount = "0.00000001",
+ noSpecAmount = "0.00000001",
+ currency = "BITCOINBTC",
+ symbol = "₿",
+ )
+
+ val specEUR = CurrencySpecification(
+ name = "EUR",
+ numFractionalInputDigits = 2,
+ numFractionalNormalDigits = 2,
+ numFractionalTrailingZeroDigits = 2,
+ altUnitNames = mapOf(0 to "€"),
)
- Amount.fromString("BITCOINBTC", "0.00000001").let { amount ->
- // Only the raw amount
- assertEquals("0.00000001", amount.amountStr)
+ amountToString(
+ amount = Amount.fromString("EUR", "1500000000.00000003"),
+ spec = specEUR,
+ rawStr = "1500000000.00000003",
+ fraction = 3,
+ specAmount = "1,500,000,000.00",
+ noSpecAmount = "1,500,000,000.00000003",
+ currency = "EUR",
+ symbol = "€",
+ )
- // The amount without currency spec
- assertEquals("0.00000001 BITCOINBTC", amount.toString(symbols =
symbols))
- assertEquals("0.00000001", amount.toString(symbols = symbols,
showSymbol = false))
- assertEquals("-0.00000001 BITCOINBTC", amount.toString(symbols =
symbols, negative = true))
- assertEquals("-0.00000001", amount.toString(symbols = symbols,
showSymbol = false, negative = true))
+ amountToString(
+ amount = Amount.fromString("EUR", "500000000.126"),
+ spec = specEUR,
+ rawStr = "500000000.126",
+ fraction = 12600000,
+ specAmount = "500,000,000.13",
+ noSpecAmount = "500,000,000.126",
+ currency = "EUR",
+ symbol = "€",
+ )
+ }
- // The amount with currency spec
- val withSpec = amount.withSpec(spec)
- assertEquals("₿0.00000001", withSpec.toString(symbols = symbols))
- assertEquals("0.00000001", withSpec.toString(symbols = symbols,
showSymbol = false))
- assertEquals("-₿0.00000001", withSpec.toString(symbols = symbols,
negative = true))
- assertEquals("-0.00000001", withSpec.toString(symbols = symbols,
showSymbol = false, negative = true))
+ private fun amountToString(
+ amount: Amount,
+ spec: CurrencySpecification,
+ rawStr: String,
+ fraction: Int,
+ specAmount: String,
+ noSpecAmount: String,
+ currency: String,
+ symbol: String,
+ ) {
+ val symbols = DecimalFormatSymbols.getInstance()
+ symbols.decimalSeparator = '.'
+ symbols.groupingSeparator = ','
+ symbols.monetaryDecimalSeparator = '.'
+ if (Build.VERSION.SDK_INT >= 34) {
+ symbols.monetaryGroupingSeparator = ','
}
+
+ // Only the raw amount
+ assertEquals(rawStr, amount.amountStr)
+ assertEquals(fraction, amount.fraction)
+
+ // The amount without currency spec
+ assertEquals("$noSpecAmount $currency", amount.toString(symbols =
symbols))
+ assertEquals(noSpecAmount, amount.toString(symbols = symbols,
showSymbol = false))
+ assertEquals("-$noSpecAmount $currency", amount.toString(symbols =
symbols, negative = true))
+ assertEquals("-$noSpecAmount", amount.toString(symbols = symbols,
showSymbol = false, negative = true))
+
+ // The amount with currency spec
+ val withSpec = amount.withSpec(spec)
+ assertEquals("${symbol}$specAmount", withSpec.toString(symbols =
symbols))
+ assertEquals(specAmount, withSpec.toString(symbols = symbols,
showSymbol = false))
+ assertEquals("-${symbol}$specAmount", withSpec.toString(symbols =
symbols, negative = true))
+ assertEquals("-$specAmount", withSpec.toString(symbols = symbols,
showSymbol = false, negative = true))
}
@Test
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-android] 07/15: [wallet] Set input digits of some amount inputs, (continued)
- [taler-taler-android] 07/15: [wallet] Set input digits of some amount inputs, gnunet, 2024/03/27
- [taler-taler-android] 01/15: [wallet] DD51: initial rendering based on currency spec, gnunet, 2024/03/27
- [taler-taler-android] 03/15: [wallet] DD51: enrich manual withdrawal amounts with currencySpecification, gnunet, 2024/03/27
- [taler-taler-android] 15/15: [wallet] Use TransactionManager.selectedScope instead of passing around scopeInfo, gnunet, 2024/03/27
- [taler-taler-android] 08/15: [wallet] Cache currencySpec in loadBalances(), gnunet, 2024/03/27
- [taler-taler-android] 10/15: [taler-android] Improve handling of currencies with no symbol, gnunet, 2024/03/27
- [taler-taler-android] 12/15: [wallet] Fix call to loadBalances() from non-UI thread, gnunet, 2024/03/27
- [taler-taler-android] 06/15: [wallet] Improve DD51 unit rendering and adapt tests accordingly, gnunet, 2024/03/27
- [taler-taler-android] 11/15: [wallet] Cache currency spec per scope info, gnunet, 2024/03/27
- [taler-taler-android] 13/15: [wallet] DD51'd more views, UX improvements and some fixes, gnunet, 2024/03/27
- [taler-taler-android] 09/15: [taler-android] Improved and refactored testToString test,
gnunet <=