feat: accept unambiguous currency names
This commit is contained in:
@@ -26,6 +26,27 @@ func calculatorConvertsYenAsJPYInEitherDirection() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func calculatorConvertsCurrencyNamesWithoutGuessingAmbiguousNames() {
|
||||
let snapshot = CurrencyRates(date: "2026-01-02", rates: [
|
||||
"eur": 1, "dkk": 8, "usd": 2, "gbp": 0.5, "btc": 0.00002,
|
||||
])
|
||||
for (query, expected) in [
|
||||
("10 euros to Danish kroner", "80 DKK"),
|
||||
("80 DANISH KRONER in euro", "10 EUR"),
|
||||
("2*5 US dollars as British pounds", "2.5 GBP"),
|
||||
("1 bitcoin to euros", "50000 EUR"),
|
||||
("10euros to DKK", "80 DKK"),
|
||||
] {
|
||||
#expect(Calculator.isCurrencyQuery(query))
|
||||
#expect(Calculator.evaluate(query, currencyRates: snapshot)?.copyValue == expected)
|
||||
}
|
||||
for query in ["10 dollars to EUR", "10 kroner to EUR", "10 pounds to EUR", "10 EUR to dollars"] {
|
||||
#expect(!Calculator.isCurrencyQuery(query, currencyRates: snapshot))
|
||||
}
|
||||
#expect(Calculator.evaluate("2 pounds to oz", currencyRates: snapshot)?.copyValue == "32 oz")
|
||||
}
|
||||
|
||||
@Test
|
||||
func calculatorConvertsFiatAndCryptoWithCaseInsensitiveSeparators() {
|
||||
let snapshot = CurrencyRates(date: "2026-01-02", rates: [
|
||||
|
||||
Reference in New Issue
Block a user