From 5a3b1d3f1912eb2b68090ec0733afa11000a3240 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 13 Oct 2023 12:37:55 -0700 Subject: [PATCH] Changed decimal formatting --- .../net/thauvin/erik/mobibot/modules/CurrencyConverter.kt | 2 +- .../thauvin/erik/mobibot/modules/CurrencyConverterTest.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt index fc56d42..41cb995 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt @@ -133,7 +133,7 @@ class CurrencyConverter : AbstractModule() { private val SYMBOLS: TreeMap = TreeMap() // Decimal format - private val DECIMAL_FORMAT = DecimalFormat("0.00") + private val DECIMAL_FORMAT = DecimalFormat("0.00#") /** * Converts from a currency to another. diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt index 59ea2e7..4ee9668 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt @@ -64,15 +64,15 @@ class CurrencyConverterTest: LocalProperties() { assertThat( convertCurrency(apiKey,"100 USD to EUR").msg, "convertCurrency(100 USD to EUR)" - ).matches("100 United States Dollar = \\d{2,3}\\.\\d+ Euro".toRegex()) + ).matches("100 United States Dollar = \\d{2,3}\\.\\d{2,3} Euro".toRegex()) assertThat( convertCurrency(apiKey,"1 USD to GBP").msg, "convertCurrency(1 USD to BGP)" - ).matches("1 United States Dollar = 0\\.\\d+ Pound Sterling".toRegex()) + ).matches("1 United States Dollar = 0\\.\\d{2,3} Pound Sterling".toRegex()) assertThat( convertCurrency(apiKey,"100,000.00 CAD to USD").msg, "convertCurrency(100,000.00 GBP to USD)" - ).matches("100,000.00 Canadian Dollar = \\d+\\.\\d+ United States Dollar".toRegex()) + ).matches("100,000.00 Canadian Dollar = \\d+\\.\\d{2,3} United States Dollar".toRegex()) assertThat(convertCurrency(apiKey,"100 USD to USD"), "convertCurrency(100 USD to USD)").all { prop(Message::msg).contains("You're kidding, right?") isInstanceOf(PublicMessage::class.java)