Add more functinos for money extension and fixed the curreny and object currency and default std money value and more

This commit is contained in:
2021-02-08 16:08:00 +07:00
parent 36599b5fb5
commit 3a7141cf76
8 changed files with 185 additions and 43 deletions

View File

@@ -5,13 +5,6 @@ import org.junit.Test
class MoneyTests {
@Test
fun exchange_2usd_to_khr_test() {
// val properties = MoneyConfig
// .MoneyConfigProperties
// .MoneyConfigPropertiesBuilder()
// .setDeliEqual(':')
// .setDeliSplit(',')
// .build()
applyMoneyConfig {
setProperties(buildMoneyConfigProperties {
setDeliEqual(':')
@@ -26,11 +19,19 @@ class MoneyTests {
// Is valid for money config?
Assert.assertTrue(MoneyConfig.isValid())
val moneyUsd = Money(2.0)
val moneyKhr = MoneyExchangeUtils.exchange(moneyUsd, MoneyCurrency.create("KHR"))
// arithmetic operators calculation
val moneyUsd =
(2 withCurrency "usd") divideWith (2 withCurrency "usd") plusOf 1 minusOf 1 plusOf 1 multiplyOf 2 divideOf 2 divideWith (8000 withCurrency "khr") plusOf 1
val moneyKhr = moneyUsd exchangeTo "khr"
// Is correct exchange?
Assert.assertEquals(8000.0, moneyKhr.getMoneyValue(), 0.0)
// complex operators and exchanging
val sum =
((moneyUsd + moneyKhr) * Money.TEN) exchangeTo MoneyCurrency.KHR minusWith (Money.ONE exchangeTo MoneyCurrency.KHR)
Assert.assertEquals(156000.0, sum.getMoneyValue(), 0.0)
}
object MyBatchRates {