Add and updated for whole the money modules with new style and some operators and computation

But money object not full implementation yet, because we need the exchange and filter the object states for money
This commit is contained in:
2021-02-08 12:39:52 +07:00
parent 19130727e3
commit 31760ee901
14 changed files with 240 additions and 71 deletions

View File

@@ -2,23 +2,10 @@ import com.cubetiqs.money.Money
import com.cubetiqs.money.MoneyConfig
import com.cubetiqs.money.MoneyCurrency
import com.cubetiqs.money.MoneyExchangeUtils
import com.cubetiqs.money.SpecialStringProcessor
import org.junit.Assert
import org.junit.Test
class MoneyTests {
@Test
fun money_operator_test() {
// val money = Money(10.0)
// val money2 = Money(20.0)
// money *= money
// println((money + money2) * money2)
// Assert.assertEquals(100.0, money.value, 0.0)
val test = SpecialStringProcessor().serialize(Money(1.0, " usd "))
println(test)
}
@Test
fun exchange_2usd_to_khr_test() {
val properties = MoneyConfig
@@ -32,27 +19,13 @@ class MoneyTests {
.setProperties(properties)
.parse("USD:1,KHR:4000")
// Is valid for money config?
Assert.assertTrue(MoneyConfig.isValid())
println(MoneyConfig.getConfig())
val moneyUsd = Money(2.0)
val moneyKhr = MoneyExchangeUtils.exchange(moneyUsd, "KHR")
val moneyKhr = MoneyExchangeUtils.exchange(moneyUsd, MoneyCurrency.create("KHR"))
// Is correct exchange?
Assert.assertEquals(8000.0, moneyKhr.getMoneyValue(), 0.0)
}
@Test
fun money_exchange_config_builder_test() {
MoneyConfig.propertiesBuilder
.setDeliEqual('=')
.setDeliSplit(';')
MoneyConfig.parse("USD:1,KHR=4000,EUR=0.99")
val moneyUsd = Money.ONE
val moneyKhr = Money.create(20000.0, MoneyCurrency.KHR)
val result = moneyUsd
}
}