Compare commits

..

No commits in common. "32441f7de67114d793d575b5f3a17cf75ca5f24e" and "3f02799284836db9a92df24890154fcfc531a1cc" have entirely different histories.

3 changed files with 9 additions and 20 deletions

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -15,11 +15,8 @@ object MoneyConfig {
* Value is the rate
*/
private val config: MutableMap<String, Double> = mutableMapOf()
// validate the config, if have it's valid
fun isValid(): Boolean {
return this.config.isNotEmpty()
}
private var valid: Boolean = false
fun isValid() = valid
/**
* Money properties for money config format
@ -61,6 +58,9 @@ object MoneyConfig {
throw MoneyCurrencyStateException("money config format is not valid!")
}
}
// validate the config is load or not
this.valid = this.config.isNotEmpty()
}
// all currencies with its rate

View File

@ -9,16 +9,13 @@ import org.junit.Test
class MoneyTests {
@Test
fun money_operator_test() {
fun 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)
}
Assert.assertEquals(10, 10)
@Test
fun exchange_2usd_to_khr_test() {
val properties = MoneyConfig
.MoneyConfigProperties
.MoneyConfigPropertiesBuilder()
@ -30,13 +27,11 @@ class MoneyTests {
.setProperties(properties)
.parse("USD:1,KHR:4000")
Assert.assertTrue(MoneyConfig.isValid())
println(MoneyConfig.getConfig())
val moneyUsd = Money(2.0)
val moneyUsd = Money(10.0)
val moneyKhr = MoneyExchangeUtils.exchange(moneyUsd, "KHR")
Assert.assertEquals(8000.0, moneyKhr.getMoneyValue(), 0.0)
Assert.assertEquals(40000.0, moneyKhr.getMoneyValue(), 0.0)
}
}